Re: Handlers in list
Re: Handlers in list
- Subject: Re: Handlers in list
- From: "Arthur J Knapp" <email@hidden>
- Date: Sat, 21 Apr 2001 14:33:31 -0400
>
Date: Sat, 21 Apr 2001 13:14:10 -0400
>
Subject: Handlers in list
>
From: "Stephen Swift (aka Burnum)" <email@hidden>
>
My goal: There are four mini-scripts that my script could perform based on
>
my input in the main-script. To break up the script, I put each mini-script
>
in a handler.
>
To choose the handler to run I used a repeat statement. The
>
repeat statement works fine when I use a list like {1,2,3,4} but when I have
>
a list of handlers, all the handlers activate. I suppose I could use if
>
then statements if all else fails. Any Ideas? Thanks.
They "activate" because you place parantheses after them, which is how
you call a handler.
>
set DlgResult to {null,null,null,null,null,null,false,true,false,false}
-- set someList to {handler1(), handler2(), handler3(), handler4()}
set someList to {handler1, handler2, handler3, handler4}
>
set Num to 1
>
repeat with i from 7 to 10
>
if item i of DlgResult = true then
>
set RunHand to item Num of someList
>
end if
>
set Num to Num + 1
>
end repeat
-- RunHand
-- Presumably, you now want to call the handler:
RunHand()
Note: This works only because the variable "RunHand" is defined
at the top-level of a script. It would not work if RunHand was
declared inside of a handler, for that, you would need to make
RunHand global:
global RunHand
on handler1()
display dialog "1"
end handler1
on handler2()
display dialog "2"
end handler2
on handler3()
display dialog "3"
end handler3
on handler4()
display dialog "4"
end handler4
set DlgResult to {null, null, null, null, null, null, false, true,
false, false}
set someList to {handler1, handler2, handler3, handler4}
ParseHandler(DlgResult, someList)
on ParseHandler(inputList, handlerList)
global RunHand
set Num to 1
repeat with i from 7 to 10
if item i of inputList = true then
set RunHand to item Num of handlerList
end if
set Num to Num + 1
end repeat
RunHand()
end ParseHandler
>
BTW - Thanks for telling me about iDo. It did exactly what I wanted.
Sure, no problem.
( "what is he talking about?"
"shhhhh, I have no idea, just take credit for it."
"ok..." )
;-)
Arthur J. Knapp
http://www.stellarvisions.com
mailto:email@hidden
Hey, check out:
<
http://developer.apple.com/techpubs/macos8/InterproCom/AppleScriptScripters
/AppleScriptLangGuide/>