10.5: AppleScript 'path to me' function changed in 10.5

Feb 28, '08 07:30:02AM

Contributed by: mark hunte

When using AppleScript, you sometimes want the running script (or AppleScript Application) to get the path to itself or a file in its resources folder. This is done by using the path to me command:

  set beep_sound to alias ((path to me as text) & ¬
  "Contents:Resources:Sounds:beep.mov") 
In 10.4, a problem I always found when writing one of these script/apps was that if you tried to test run them in Script Editor, the path to me function would return the path to Script Editor. There where ways around this, but it meant editing the script/app just to test. In 10.5, however, as long as you save the script/app first, then the path to me function will return the correct path to the script/app when tested in Script Editor.

As an example, this code...
 "display dialog ("The path to me is : " & return & (path to me))" 
...when run in 10.4's Script Editor from a saved script will return:
The path to me is : Macintosh HD:Applications:AppleScript:Script Editor.app:
In 10.5, though, it will display:
The path to me is : Macintosh HD:Users:username:path:to:foo.scpt
[robg adds: I can't easily test this on 10.4, but I can confirm the 10.5 behavior.]

Comments (3)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20080223103121102