Reputation: 6730
The line:
set appPath to POSIX path of alias ":Applications:iTunes.app"
works fine in AppleScript Editor and returns: "/Applications/iTunes.app/"
But when I run the following command in the terminal:
osascript -e 'set appPath to POSIX path of alias ":Applications:iTunes.app"'
I get: 15:61: syntax error: File alias :Applications:iTunes.app wasn't found. (-43)
Why?
Upvotes: 0
Views: 1052
Reputation: 19032
I'm not sure where you came up with ":Applications:iTunes.app"... but that is not a valid path. Colon delimited paths that are used in applescript always start with the name of your hard drive. So it should be something like "Macintosh HD:Applications:iTunes.app:". I can't tell you why it works in applescript editor (you're just lucky I guess ;)), but I'm sure if you try it the correct way it will work.
Notice that the path I used ends with a colon eg. "Macintosh HD:Applications:iTunes.app:". In general applications are package files which means they're really folders... and folders end in a colon.
Note that when you coerce a string like ":Applications:iTunes.app" to an alias (as you're doing by putting the word alias first), because it's an alias it means that the file at the path must exist. That's the definition of an alias-type path. The file must exist. And because the file can't possibly exist because of your incorrect path then you get the error.
Another note: the "posix path" coercion will work on a string so you really don't need the word "alias" at all... although you may get unexpected results because as I mentioned the string portion of your path is not correct (sorry to keep saying that!).
Final note: here's one way you can find the correct applescript-style path to a file. Just run this and look at the result in AppleScript Editor. This will work for folders too if you change "file" to "folder" in the code. Try it out on an application and you will see that if the application is a package file then it will end in a colon.
(choose file) as text
Anyway, I hope that teaches you something as you go forward with your applescripting.
Upvotes: 4