Re: Path to me Caveat
Re: Path to me Caveat
- Subject: Re: Path to me Caveat
- From: Paul Skinner <email@hidden>
- Date: Fri, 12 Oct 2001 08:52:46 -0400
on 10/12/01 5:09 AM, JJ wrote:
>
> --begin script
>
> --running in an editor or an an applet.
>
> property parent : application "Finder"
>
> display dialog ((path to me) as text)
>
> -->"OS9:System Folder:Finder"
>
> --end script
>
>
>
> In these cases, I have no idea how to find the script's location from
>
> within itself. Maybe somebody here will show me how.
>
>
property parent : application "Finder"
>
set MeScript to ":" & "TestScript" as alias
>
Thanks JJ!
I forgot that trick. This works in great for applets, just not in the
editors.
-->OS9:Desktop Folder:folder holding test app:pathtometest
vs.
-->ERROR - "File OSX:Applications:Applications (Mac OS
9):AppleScript:Scripter. 2.5:pathtometest wasn't found."
Not a big deal, I don't use 'path to me' for any scripts currently, and if I
did, I could code around this when running them in the editor.
>
(":" as alias) always returns the folder containing the running script: the
>
Script Editor (parent: script editor/debugger/...), if the script is running
>
inside it, or the applet/droplet's folder (parent: script Applescript).
>
>
If you need some parents, you can "define" it into "child objects":
>
>
--- s t a r t s s c r i p t ---
>
tell ParentFinder to DisplayDialog()
>
display dialog (path to me)
>
>
script ParentFinder
>
property parent : application "Finder"
>
on DisplayDialog()
>
display dialog (path to me) as text
>
end displaydialog
>
end script
>
--- e n d s s c r i p t ---
>
--> "HD:System Folder:Finder"
>
--> "HD:Desktop Folder:TestScript"
>
>
The child object "ParentFinder" defines its own parent. So, if you delente
>
the "property parent..." line, it returns its "default" parent: the script.
>
--> "HD:Desktop Folder:TestScript"
>
>
JJ
In this case you've solved the problem, but only by removing the cause.
The parent property.
I use the parent property to give access to my library of handlers to
all of my scripts through inheritance. If I applied this solution to my
scripts it would break everything I've ever written, or require extensive
re-telling i.e.'tell the script to do whatever' yuck. I'll have nightmares
just from thinking about that kind of thing.
Your (":" as alias) solution is just the thing though! Thanks again.
--
Paul Skinner