On Feb 11, 2014, at 6:02 AM, Jim Brandt wrote: Here's a script representing my library:
on ScriptA() display dialog (path to me) as text end ScriptA
save it as a script bundle named ScriptA and run it using a second script:
set sa to load script alias (((path to desktop) as text) & "ScriptA.app")
sa's ScriptA()
the display points to the call script's path
save ScriptA as an application and the result is the same.
What I want is the path to the ScriptA, not to the calling script. I want to store resources in the script bundle of ScriptA, and have ScriptA know how to retrieve those resources, no matter where ScriptA is stored. (using a path to resource folder in ScriptA). Instead, I'm getting the path to the resource folder of the calling script.
I am going to have to do some experimenting to see if this can be done, but I can see from your code why you are not getting what you want.
In your Main application script, you use ...
set sa to load script alias (filePath)
This copies the code from filePath into Main, then you use ...
which runs code that is now in Main. (Code was copied from ScriptA, but is now located in Main.) This causes path to me to report its correct location as the path to Main.
You might want to experiment with using 'run script', instead of 'load script'. This will make the code run within its desired location.
Here is what I just tested:
-- saved as an application bundle named "scriptA.app" on ScriptA() set pathToMe to ((path to me) as text) display dialog pathToMe end ScriptA
and
-- saved as an application bundle named "Main.app" property pathToScript : alias "OS_X:Users:lutherfuller:Desktop:test folder:scriptA.app" on run set appPath to (pathToScript as text) launch application appPath tell application appPath to ScriptA() -- or use activate or run without launch
beep delay 1 end run
This seems to behave according to your specifications. CAUTION: I have used launch application ... in "Main.app". This does NOT work correctly in Mt. Lion and Mavericks.
|