Re: How to do a goto with Applescript?
Re: How to do a goto with Applescript?
- Subject: Re: How to do a goto with Applescript?
- From: Skeeve <email@hidden>
- Date: Tue, 11 Jan 2011 22:30:49 +0100
Am 10.01.11 19:01, schrieb Robert Poland:
Please be kind with your remarks.
No remarks but maybe this pattern helps?
I have a set of prepare_PROGRAMNAME handlers.
Each of those returns a script having a process() handler.
Each of the prepare_PRGRAMNAME handlers' values is associated to a
programname in a list of records like this:
{ nme: "Finder", hdlr: prepare_Finder() }
When you have a programname, you compare it to each of the "nme" items
in the list. Having found a match you execute the "hdlr" item's
process() of the found match.
This way you simply need to
a) add a new prepare_PROGRAMNAME for each new program
b) specify what process() needs to do
c) add an entry in the "programs" list
-----------------------------------
on run
-- list of known programs
set programs to {{nme:"Finder", hdlr:prepare_Finder()}, ¬
{nme:"Acrobat", hdlr:prepare_Acrobat()}, ¬
{nme:"Mail", hdlr:prepare_Mail()}}
repeat
-- get a programname from somewhere
set chosen to choose from list {"Finder", "Acrobat", "Mail"}
-- Cancel was clicked
if chosen is false then
return
end if
set chosen to first item of chosen
-- loop through all known programs
repeat with program in programs
-- check for match
if chosen contains nme of program then
-- execute the matches process handler
tell hdlr of program to process()
-- and leave the loop as we found the match
exit repeat
end if
end repeat
end repeat
end run
-- these handlers only display a dialog. Feel free to add what you want
on prepare_Finder()
script hdlr
to process()
display dialog "Finder"
end process
end script
return hdlr
end prepare_Finder
on prepare_Acrobat()
script hdlr
to process()
display dialog "Acrobat"
end process
end script
return hdlr
end prepare_Acrobat
on prepare_Mail()
script hdlr
to process()
display dialog "Mail"
end process
end script
return hdlr
end prepare_Mail
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden