Re: Who called?
Re: Who called?
- Subject: Re: Who called?
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 16 Jan 2001 20:33:10 -0800
On 1/16/01 11:39 AM, "Dave Saunders" <email@hidden> wrote:
>
I'm writing a bunch of scripts that are used either from the OSA menu or
>
from OneClick. They are all structured like this:
>
>
try
>
blah...blah...blah
>
return "OK"
>
on error
>
return ErrorMsg
>
end try
>
>
This works well for OneClick because it means that my AppleScripts always
>
return a value for it to chew on, even when they pull unexpected errors.
>
>
But, if I run that same script from the OSA menu and an error occurs, the
>
return error message has nowhere to go.
>
>
So, what I want to do is:
>
>
>
try
>
blah...blah...blah
>
return "OK"
>
on error
>
if OneClick called me then
>
return ErrorMsg
>
else
>
display dialog ErrorMsg
>
end if
>
end try
>
I'm not being rigorous with my syntax here, but you get the idea. The
>
question is, how do I do the test (if it's easier to test for OSA, then I
>
can reverse the if...then...else)?
You can do it either way.
There's a coercion in OSA Menu (thank you, Leonard) that treats compiled
scripts there as if they were applications. The result of
path to me
is the path name of the script (as alias, or else specify 'as string').
whereas the path name of a compiled script running from an application is
the application's file itself. I've just tested - the result of (path to me)
in an embedded AppleScript in a OneClick button is the path name of the
frontmost application, whatever it is. So:
AppleScript
set p to ((path to me) as string)
set {ods, AppleScript's text item delimiters} to {AppleScript's text
item delimiters, {":"}}
set ap to last text item of p
set AppleScript's text item delimiters to ods
if ap = "NameOfFrontProcess" then -- put real app's name here
set returnHow to "Send to OC"
else
set returnHow to "OSA, so dialog"
end if
(* --or if it works better for you:
if ap = "NameOfThisScript" then -- put real script name here
set returnHow to "OSA, so dialog"
else
set returnHow to "Send to OC"
end if *)
try
--do your stuff here
on error errMsg
if returnHow = "OSA, so dialog" then
display dialog errMsg
else
return errMsg
end if
end try
End AppleScript
--
Paul Berkowitz
References: | |
| >Who called? (From: Dave Saunders <email@hidden>) |