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: "email@hidden" <email@hidden>
- Date: Wed, 12 Jan 2011 09:21:32 -0800
> Yes. There's nothing wrong with "if" or "else if". The problem is
> with giant hunks of inline code:
Or if each condition issues basically the same commands with different values.
Even then it's not that major a problem, especially if the script works! However, it is much easier to maintain and trouble shoot your script if you break the parts that are receptive and/or do the heavy lifting into handlers.
> Ideally, what you want is for each clause of the if/else to be only a
> few lines. One way to do that is to move the logic into handlers:
>
> if condition then
> handleCondition()
> else if other_condition then
> handleOtherCondition()
> ...
> end
In the case of your script it could look like this:
if condition then
handleCondition(currentFrontApp, montitorSize, macType)
else if other_condition then
handleCondition(currentFrontApp, montitorSize, macType)
end
on handleOtherCondition(frontApp, sizeOfMonitor, typeOfMac)
--You could use the same variable names inside the handler too, but I prefer changing them
end
> 2. Would the creation of multiple data files (one for each monitor) and a handler for each application window instead of using the "else if" statement be as fast or faster to run? I would assume that a data file would have to be read every time the script is run.
I would suggest creating a single data file and reading that first thing in your script.
Or, as Mark suggested, you could also create a single script, or one for each case, that your script would load and execute as a script object. (easier than it sounds)
ES
_______________________________________________
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