Re: Running from what?
Re: Running from what?
- Subject: Re: Running from what?
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 24 Nov 2000 17:06:21 -0800
On 11/24/00 4:03 PM, "Dave Saunders" <email@hidden> wrote:
>
Is there a way to detect from where a script is being run? I'm creating a
>
suite of scripts that I intend be driven by a set of OneClick buttons, but
>
I'm also making them available from the OSA menu (and, during testing, I run
>
them with Script Debugger).
>
>
Because of problems with OneClick not always being able to recover when an
>
AppleScript craps out with an error, I'm trying to make sure that never
>
happens by passing error messages back to the OneClick button to display
>
(rather than use Display Dialog in the error handler). But that won't work
>
if run from the OSA menu.
>
set p to ((path to me) as string)
set {ods, AppleScript's text item delimiters} to {AppleScript's text
item delimiters, {":"}} -- one line
set ap to last text item of p
set AppleScript's text item delimiters to ods
ap
will give you, normally, the name of the application file of the application
running the script.
If your script is actually an applet, then 'ap will return the name of the
applet, whatever may be 'driving' it.
Running a compiled script from OSA Menu, 'ap' will also give you the name of
the script, as if it were an applet.
If running from Script Debugger, 'ap' will be "Script Debugger".
But, oddly enough, your two circumstances are "special situations":
If placed in embedded AppleScript in a OneClick button script, 'ap' will
give you the name of the application in the front, even if running from a
global palette. So it will say "Finder" or "Outlook Express" or whatever s
in front. ***OneClick itself never has any "existence" as an app this way.
You won't ever get the name "OneClick" this way. But maybe it's not embedded
applescript, or you wouldn't have this problem in the first place. If you're
simply using OneClick to tell the script (which is where? is it an applet,
or in OSA menu?) to run, then you won't be able to tell the difference. This
is not the right way to go.
So this is what I'd suggest: DON'T just just call the script from the OC
buttons - embed it. Then you won't even need to test for 'path to me', since
you KNOW it's running from an OC button. Just write it differently:
Variable eOC
AppleScript
try
-- your script
set OneClick variable "eOC" to "OK"
on error errMsg
set OneClick variable "eOC" to errMsg
end try
End AppleScript
If eOC <> "OK"
Message eOC
End If
And in the script running from OSA Menu:
try
--your script
on error errMsg
display dialog errMsg
end try
You can do this wherever in the script you want to error-trap (i.e. it
doesn't have to surround the whole script as above).
Is there some reason why this won't work?
--
Paul Berkowitz