Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I have these two Applescript commands in which they both point to the same file

alias "Macintosh HD:Users:scott:Dropbox:Downloads:AppleScriptFinderGuide.pdf"
file  "Macintosh HD:Users:scott:Dropbox:Downloads:AppleScriptFinderGuide.pdf"

The alias command works just fine. However the file command does not as it reports this error: "Can’t get file "Macintosh HD:Users:scott:Dropbox:Downloads:AppleScriptFinderGuide.pdf"."

Any idea why the file command fails?

Thanks in advance, Scott

share|improve this question
    
shouldn't file get the path with slashes / instead of semi colon : ? –  CousinCocaine Aug 3 at 20:58
    
colons are used for Applescript paths. I know its very old skool well so is Applescript. –  Scott Walter Aug 3 at 23:19

2 Answers 2

up vote 2 down vote accepted

You are not referencing the file correctly.

Try

tell application "Finder" to set myFile to file "Macintosh HD:Users:scott:Dropbox:Downloads:AppleScriptFinderGuide.pdf"
share|improve this answer

It's not an alias or file command - these are object specifiers. AppleScript proper does not recognize a standard file object, although many applications such as the Finder do.

You can create a file URL object (similar to a file object) outside of an application context that most apps will recognize:

set myFile to "Macintosh HD:Users:scott:Dropbox:Downloads:AppleScriptFinderGuide.pdf" as «class furl»

tell application "Finder"
  reveal myFile
end tell

But in general I use aliases everywhere or plain-text HFS path strings, because these can be coerced to anything necessary without having to worry about quoting spaces or special characters.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.