Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

(path to me) question

More than one forum member has suggested using :: set filePath to (path to me as string) & "Contents:Resources:" & "<file>" :: to get the path to a file in the resources folder of a script bundle.

but, for me, that yields (for example)
MAC HD:TEST:Test.app:Contents:Resources:Scripts:main.scptContents:Resources:ASA

and I have to remove "Scripts:main.scptContents:Resources:" to get a path to the file that works.

I mentioned this in a previous post and Cyclo commented "That's very odd."
It's not a big deal, but do others not run into this?

2.7G5 AND OTHERS, Mac OS X (10.4.6)

Posted on Jul 19, 2007 4:20 AM

Reply
Question marked as Best reply

Posted on Jul 19, 2007 6:05 AM

More than one forum member has suggested using ::
set filePath to (path to me as string) &
"Contents:Resources:" & "<file>" :: to get the path
to a file in the resources folder of a script
bundle.

but, for me, that yields (for example)
MAC
HD:TEST:Test.app:Contents:Resources:Scripts:main.scptC
ontents:Resources:ASA

and I have to remove
"Scripts:main.scptContents:Resources:" to get a path
to the file that works.

I mentioned this in a previous post and Cyclo
commented "That's very odd."
It's not a big deal, but do others not run into this?


On one hand I could see how you would get the results that you are getting since a script that's been saved as an "application bundle" typically resides within the Contents/Resources/Scripts folder of the .app bundle.

However, it doesn't do that for me. This short script, saved as an application bundle simply returns the path to the .app bundle/folder that contains the script (and not the full path to the .scpt file).
<pre>
on run

set p to (path to me as string)
display dialog "Path: \"" & p & "\""

end run</pre>
What do you get if you run a simple little script like this? Maybe there's something flakey about the app bundle you're currently working on? Have you tinkered with some of the internal components of the bundle that may be causing you to get different results?

Steve

20" iMac G5 Mac OS X (10.4.10)
4 replies
Question marked as Best reply

Jul 19, 2007 6:05 AM in response to osimp

More than one forum member has suggested using ::
set filePath to (path to me as string) &
"Contents:Resources:" & "<file>" :: to get the path
to a file in the resources folder of a script
bundle.

but, for me, that yields (for example)
MAC
HD:TEST:Test.app:Contents:Resources:Scripts:main.scptC
ontents:Resources:ASA

and I have to remove
"Scripts:main.scptContents:Resources:" to get a path
to the file that works.

I mentioned this in a previous post and Cyclo
commented "That's very odd."
It's not a big deal, but do others not run into this?


On one hand I could see how you would get the results that you are getting since a script that's been saved as an "application bundle" typically resides within the Contents/Resources/Scripts folder of the .app bundle.

However, it doesn't do that for me. This short script, saved as an application bundle simply returns the path to the .app bundle/folder that contains the script (and not the full path to the .scpt file).
<pre>
on run

set p to (path to me as string)
display dialog "Path: \"" & p & "\""

end run</pre>
What do you get if you run a simple little script like this? Maybe there's something flakey about the app bundle you're currently working on? Have you tinkered with some of the internal components of the bundle that may be causing you to get different results?

Steve

20" iMac G5 Mac OS X (10.4.10)

Jul 20, 2007 5:43 AM in response to Steve Herman1

Hi Steve,

Well, this may turn out to be a little more messy than I expected -- but maybe I'm going about things wrong.

In a nutshell, if, after I've saved a script as an application bundle, I decide the script needs editing, I've been accessing the script via "Show Package Contents" -- and that appears to be where the trouble starts. The script, retrieved in that manner, has the added information in the path. If I try to evaluate my editing by running that script, it crashes on the path. If I add a routine to correct the path, the script will run from that window but the routine then gets saved back to the app, which may crash because of the routine (which it doesn't need).

To make matters really confusing, AppleScript Editor and Script Debugger (which I've been using recently) act somewhat differently. Here are details of what happens with both editors:

In AppleScript Editor:

Write Script & compile
Save to desktop as application bundle "SH.app" (title of AS window remaining on desktop changes to SH.app)
Run from window remaining on desktop with resulting dialog:


"Path: "MAC HD:Applications:AppleScript:Script
Editor.app:Contents:Resources:ASA"

>> Incorrect path if run from this window <<

<div class="jive-quote">Close remaining window
Double-click on desktop app with resulting dialog:

"Path: "MAC
HD:Users:osimp:Desktop:SH.app:Contents:Resourc
es:ASA"

>> Which is the correct path <<

<div class="jive-quote">Control-click on desktop app and choose Show Package Contents, navigate to main.scpt and open that (title will be "main.scpt")
Run script from that window with resulting dialog:


"Path: "MAC HD:Applications:AppleScript:Script
Editor.app:Contents:Resources:ASA"

>> Incorrect path if run from this window <<

In Script Debugger:

The corresponding three dialogs are:

"Path: "MAC
HD:Users:osimp:Desktop:SH.app:Contents:Resourc
es:ASA"

>> Which is the correct path <<

"Path: "MAC
HD:Users:osimp:Desktop:SH.app:Contents:Resourc
es:ASA"

>> Again, the correct path <<

"Path: "MAC
HD:Users:osimp:Desktop:SH.app:Contents:Resourc
es:Scripts:main.scpt:Contents:Resources:ASA"

>> Incorrect path if run from this window <<

I haven't really had time to think this out in terms of the best way to edit (and test) a script already saved as an application bundle.

Jul 20, 2007 8:21 PM in response to osimp

With Script Editor when you run a script within the editor and attempt to use "path to me" you will get back the path to Script Editor itself (because Script Editor is the application that is running and it's executing your script within it's own process). But when your execute your script by double-clicking in the Finder you get the result you expect (because you're no longer running within Script Editor). Script Editor has always acted this way and it makes it painful to develop and test scripts within the editor if they depend on "path to me".

I haven't used Script Debugger in years (since OS 9) but I know that one of it's features has always been the added functionality of "knowing" that it should manipulate the result of "path to me" give you back the same result you would get if your script was running from Finder. I don't know why Apple has never added this feature to Script Editor.

See the "AppleScript support of self" section near the bottom of this fairly old web page from 2000 that shows the different results from various script editors when using "path to me".

So the above explains all three Script Editor results and the first two Script Debugger results. The only somewhat surprising result of your experiments was the last (incorrect) path returned when using Script Debugger to open a script file directly within your app's bundle.

I suspect this is most likely a side effect of doing a "show package contents" and drilling down to the actual script file to open it. I'm thinking that when you open the script directly like this it may be confusing Script Debugger's ability to return the expected result. At this point maybe it doesn't really know that it's dealing with a .scpt file that's within an application bundle so it's giving you the full path to the script itself. However, I bet that if you instead opened your script by dragging and dropping your .app bundle onto Script Debugger's icon it would then know that it was dealing with a script within a bundle and give you the expected result for "path to me". (It would also save you the hassle of having to manually open the package contents and drill down to the .scpt file.)

Steve

20" iMac G5 Mac OS X (10.4.10)

Jul 21, 2007 8:34 AM in response to osimp

-- However, I bet that if you instead opened your script by dragging and dropping your .app bundle onto Script Debugger's icon it would then know that it was dealing with a script within a bundle and give you the expected result for "path to me". (It would also save you the hassle of having to manually open the package contents and drill down to the .scpt file.)

So far, this seems to be an ideal solution.

Thanks, Steve!

(path to me) question

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.