Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative file paths with Applescript

I'm trying to make an Applescript that will open a file on a user's computer without knowing the hard drive or user name, presuming the file is in the same place in the user directory.

tell application "Finder" to open "/Users/jim/Dropbox/Getting Started.pdf" as POSIX file

works great, whereas

tell application "Finder" to open "~/Dropbox/Getting Started.pdf" as POSIX file

fails.

Is there any way to accomplish this simply?

like image 799
Calion Avatar asked Jun 10 '14 23:06

Calion


1 Answers

You can't use tilde paths in AppleScript basically because POSIX file is in fact an URL. URLs for file paths doesn't support incremental paths, only absolute paths. But the meaning of the tilde in POSIX paths is not something special, it's just replaced by the home folder. SO to get the same results we only need to change your code to:

tell application "Finder" to open (POSIX path of (path to home folder)) & "Dropbox/Getting Started.pdf" as POSIX file
like image 81
dj bazzie wazzie Avatar answered Oct 25 '22 15:10

dj bazzie wazzie