Re: Relative path (Jolly Roger)
Re: Relative path (Jolly Roger)
- Subject: Re: Relative path (Jolly Roger)
- From: Paul Berkowitz <email@hidden>
- Date: Thu, 21 Dec 2000 02:05:15 -0800
On 12/21/00 1:29 AM, "Nir Soffer" <email@hidden> wrote:
>
I can not have the problem of a missing script, because a missing script
>
would not show up in the script menu of applications like Powermail or
>
BBEdit. These application show in the menu the script that exists in the
>
scripts folder.
>
You'd be surprised, if it concerns another script. But if you're looking
for "itself" that should be so hard. Scripts running from internal script
menus have to be placed in specific folders. Sometimes you will know exactly
where that folder is, or you can ask.
>
The problem is how to make a generic script thats know the path to itself
>
when you run it as compiled script using these applications script menu.
>
If you want to take a little risk that the scripts folder won't be moved
from its default location, you can look for it there. In many apps, the
script folder will be in the same folder as the application file. So you
could do:
set appFile to (path to me) -- the application running the script, or
tell application "Finder"
set appFile to application file id "xxxx" -- code for app
set outerFolder to container of appFile as alias
end tell
--if that's what you're looking for, stop here
--find the actual script?
set scriptFolderpath to (outerFolder as string) & "Script Folder Name" & ":"
try
set theScript to alias (scriptFolderpath & scriptName)
on error
display dialog "! Someone changed the name of the script or script
folder, or the location. Bad!" buttons {"OK"} default button "OK" with icon
0
return
end try
A lot safer would be to do what I suggested earlier and ask the user to
select the script and store it as an alias. It will work equally well for
itself as for other scripts. Alternately, you could use 'choose folder' to
find the scripts folder, if that's what you're looking for. Very simple.
Then save the folder as an alias in a script property. You should just do
what I suggested before, but leave out the test for existence if you want
to, since both the script and the scripts folder obviously exist if it's
running. (I hadn't remembered you were looking for the script itself, and
gave you a generic solution.)
It should be becoming clear by now that there is no simple equivalent of
(path to me) for compiled scripts. You can keep on asking, but you're not
going to get the sort of answer you're hoping for. So think over these two
solutions and figure out which would be better for you: one where you don't
have to ask the user, but might fail in the situation that the user has
renamed it or moved the script folder, or ask the user the very first time
only (it will never ask again) and be 100% sure of finding it even if it's
renamed or moved.
--
Paul Berkowitz