Re: Variables inside handlers
Re: Variables inside handlers
- Subject: Re: Variables inside handlers
- From: email@hidden
- Date: Wed, 11 Dec 2002 12:48:50 -0500
Message: 1
On Wed, 11 Dec 2002 16:41:31 +1100, The Other Rob <email@hidden>
asked,
>
OK, I've been reading these replies and scratching my head
>
for half an hour, and I'm thinking that my original post might
>
not make much sense...
>
>
The first script ...
>
>
ignoring application responses
>
launch application "OSX:test3app"
>
run application "OSX:test3app"
>
tell application "OSX:test3app" to somehandler("$1", "$2", "$3")
>
end ignoring
This probably won't do what you want. When you say "ignoring application
responses" that means, "don't wait for anything." That means that the
"somehandler()" message will be thrown at test3app before it has a chance to get
started and start listening for messages. The message will probably be dropped
on the floor and lost.
Doing both launch and then run are unnecessary. There are some subtleties of
what happens with the idle handler and the when you launch a script app versus
running it, and some other issues involving running something twice, but I don't
think you need to get into that.
There is also a bug in some versions of AppleScript (prior to 1.8.3) that make
an applet ignore messages sent to it if it isn't running first. If this bug is
not present in your system, you can simply call your handler without any
preliminary "run" or "launch". (I can't find the details of when this bug
appeared and when it was fixed. It particularly impacted people using
AppleScript for web CGIs and to extend ListSTAR. I've verified that its not
present in 1.8.3 under OS 9.2.2 with Script Editor 1.8.3)
So if you are using a version of AppleScript with this bug, you may need to run
or launch the app first, but you don't need to do both. And you definitely
don't want to ignore application responses, since in that case you won't wait
until the application is ready to receive further messages, and you'll have your
message dropped.
To test for the bug, use these scripts:
-- Save this as "Tester", with "Stay Open" and "No Startup Screen"
on test()
say "Hello"
end test
Next, run this script from Script Editor
tell application "Tester" to test()
Make sure Tester isn't running. If Tester says "Hello", you don't have the bug,
and can dispense with any "launch" or "run". If you get "Apple Event Timed
Out", you need to launch or run first. If you get "Insufficient memory", you
need to give Tester more memory. (On older systems, applets were saved with a
memory setting too small for them to use the "say" command.)
>
... is actually something I added to 'mailScript.applscript'
>
which is an AppleScript that iCal runs to send mail when a
>
calendar event is reached, and those variables ("$1", "$2", "$3")
>
are generated by iCal. The idea was that iCal would run
>
'mailScript.applscript', and the code I added to it
>
would in turn run my own script application (test3app)
>
and pass the variables to it.
You can't pass the names of the variables, you have to pass their values. The
code in your modified mailScript.applscript would look like,
tell application "OSX:test3app" to somehandler($1, $2, $3)
and inside test3app you would work with these parameters like any arguments to a
handler:
on somehandler(a, b, c)
display dialog a
end somehandler
>
The problem is that after the variables are parsed to 'test3app', they
>
aren't accessible outside of the handler.
AppleScripting isn't smooth when you try to pass names of variables around.
Usually you pass the values. On special occasions, you can pass a reference to
a variable, but usually that leads to convoluted code, so you should avoid it
unless necessary. Passing the name of a variable is possible, but that requires
you to do "compile on the fly" things that are slow and difficult to write.
In your application, it looks like you just need to pass along the values that
iCal gives you.
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden
_______________________________________________
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.