Re: Call a handler from applescript
Re: Call a handler from applescript
- Subject: Re: Call a handler from applescript
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 30 Jan 2004 09:57:48 -0800
On 1/30/04 5:27 AM, "Walter Ian Kaye" <email@hidden> wrote:
>
At 01:05p +0000 01/30/2004, Yan Wong didst inscribe upon an electronic
>
papyrus:
>
>
> A pretty basic question, but I'm new to applescript programming.
>
> How, from the outside, can I call a handler in an scriptable AS
>
> Studio application.
>
>
>
> In other words, I have an Applescript application called "Signal" containing
>
>
>
> on my_signal(txt)
>
> display dialog txt
>
> end my_signal
>
>
>
> Which I place in /Applications. I wish to run another applescript
>
> that does something like
>
>
>
> tell application "Signal"
>
> my_signal("hello")
>
> end tell
>
>
>
> I imagined that this was what the "call method" function did, but
>
> that doesn't work either. I'm sure I'm just missing something
>
> obvious.
>
>
Hmm. It works for "regular" applets made by Script Editor.
>
Maybe AS Studio apps require a different technique?
This isn't a Studio application, I don't think. It's an applet. The problem
derives from the fact that all applets have the same creator code "aplt",
rather than a unique creator code such as commercial application have. Your
system does not know 'application "Signal"' and probably picked some other
applet on Yan's computer, which does not have a my_signal handler.
If this is just for your own use, just hardcode the full path to the applet
in:
set appletPath to ((path to applications folder as Unicode text) &
"Signal")
tell application appletPath to my_signal("hello")
If it's for other users, you can ask them to locate the app first time with
'choose file' and save the result as an alias rather than text path. Then
they can move it, rename it etc. whenever they want. In your code you will
first have to cast the alias to Unicode text (the path) before using it:
property appAlias : missing value
if appAlias is not missing value then
try -- it may be deleted
get appAlias
on error
set appAlias to missing value
end error
end if
if appAlias = missing value then
set appAllias to (choose file of type "APPL" with prompt "Locate
\"Signal\" application")
end if
set appPath to appAlias as Unicode text
tell application appletPath to my_signal("hello")
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.