AppleScript code for determining if file exists

Delurking for a quick code snippet. I needed to have AppleScript check to see if a file exists before doing something. Initially I was trying to do this with a bare if *filepath* exists, until ninety seconds of searching revealed something obvious. You need to tell the Finder to do it.

For example…

tell application "Finder"
    if exists file "Macintosh HD:Users:chrisb:Documents:test file.txt" then
        display dialog "it exists"
        display dialog "it does not exist"
    end if
end tell

About Chris Barrus

You are not cleared for this information.
This entry was posted in Apple. Bookmark the permalink.

Leave a Reply

Your email address will not be published.