Re: Variables inside handlers
Re: Variables inside handlers
- Subject: Re: Variables inside handlers
- From: The Other Rob <email@hidden>
- Date: Wed, 11 Dec 2002 16:41:31 +1100
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
... 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.
The problem is that after the variables are parsed to 'test3app', they
aren't accessible outside of the handler.
Does all that make sense? I apologise for my ramblings... ;)
Thanks again for your help,
-Rob
on 11/12/02 4:09 PM, Ben Waldie (AppleScript Guru) at
email@hidden wrote:
>
Rob,
>
>
On Tuesday, December 10, 2002, at 11:48 PM, The Other Rob wrote:
>
>
> My problem is that the scope of the variables (test1, test2, test3) is
>
> limited to that particular handler, and I can't access them from other
>
> parts
>
> of my test3app script. Is there any way to make these variables
>
> available
>
> to the rest of my script?
>
>
There are a few things you can do.
>
>
1) You could return the variable values to the code/script that's
>
calling your subroutine.
>
>
on someHandler()
>
set x to 1
>
set y to 2
>
set z to x + y
>
return {x, y, z}
>
end someHandler
>
>
Then, from the loaded script, simply say something like...
>
>
tell theLoadedScript to set myVariables to someHandler()
>
>
>
2) You could declare your variables as globals.
>
>
on someHandler()
>
global x, y, z
>
set x to 1
>
set y to 2
>
set z to x + y
>
end someHandler
>
>
Then, from the loaded script, simply say something like...
>
>
global x, y, z
>
tell theLoadedScript to someHandler()
>
x
>
y
>
z
>
>
3) You could use properties to store your variables.
>
>
property x : 0
>
property y : 0
>
property z : 0
>
>
on someHandler()
>
set x to 1
>
set y to 2
>
set z to x + y
>
end someHandler
>
>
Then, from the loaded script, simply say something like...
>
>
tell theLoadedScript to someHandler()
>
x of theLoadedScript
>
y of theLoadedScript
>
z of theLoadedScript
>
>
>
Hope this helps. Thanks,
>
>
- Ben
>
>
Benjamin S. Waldie
>
AppleScript Guru
>
>
http://www.applescriptguru.com
>
_______________________________________________
>
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.
_______________________________________________
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.