Search code examples
datefindapplescriptfile-type

list all files modified today with type "adobe photoshop..." in applescript


I am creating a script for billing purposes at work that can count all files modified on the day it's run and are of type "Adobe Photoshop ..." (for example "Adobe Photoshop file", "Adobe Photoshop JPEG file", "Adobe Photoshop TIFF file").

I can't just search for "images" because then the script lists the original files as well (only when a file was saved in photoshop (modified at the office) will it change the type to "Adobe Photoshop ____ file").

I have this so far:

with timeout of (5 * 60) seconds
    set root_fol to (choose folder)

    tell application "Finder"
        set files_ to count ((files of entire contents of root_fol) whose modification date is greater than ((current date)) - 1 * days)
    end tell

    display dialog (files_)
end timeout

But it doesn't look for files modified today. Instead, it looks for files modified within the past 24 hours -- for example, when you run the script at 18:00 today, it will also give you the files last modified yesterday, but after 18:00.. (and it searches for all files, not just Photoshop files)

So in short I would like to mimic the process of going in the search bar of Finder and looking for for date modified is today and kind is other: "adobe photoshop"


Solution

  • You need to use a range. So you should be searching for midnight to midnight like this...

    set fl to path to downloads folder from user domain as alias
    set ds to date string of (current date)
    
    # Today at midnight
    set t to date (ds & " 12:00:00 AM")
    
    # Yesterday at midnight
    set y to t - 1 * days
    
    tell application "Finder"
        set fc to count ((files of entire contents of fl) whose modification date is greater than y and modification date is less than t)
    end tell
    

    This use of Finder btw appears very slow on my Snow Leopard. There are faster ways, using spotlight through the shell command. See this for details.

    EDIT: for file type you can use

    and kind is "text" or and kind contains "text" in the Finder search. More info here.