Re: how long can an applescript be?
Re: how long can an applescript be?
- Subject: Re: how long can an applescript be?
- From: Paul Berkowitz <email@hidden>
- Date: Mon, 20 Jan 2003 15:54:11 -0800
On 1/20/03 2:45 PM, "Michael Glasser" <email@hidden> wrote:
>
I have a script that has gotten pretty long... for me anyway... about
>
2000 lines. The whole script is a big repeat loop.... it checks to see
>
if new text has been added to a file, if it fits some basic patterns,
>
and, if so, does a lot of parsing and creation of new text based on it.
>
It then sends the text to another application...
>
>
all is good, except it does not allow me to stop it.. the stop button
>
does not work, nor does Apple+period. I can quit it from the Dock, and
>
it will even ask me to save changes MOST of the time. Other times I
>
have to force quit.
>
>
It also will not run as a stand alone app... I get an error message
>
that says "O doesn't understand the count message" with the typical
>
"edit" button. I have nothing called "O" - when I press the edit
>
button the script opens but nothing is selected.
>
>
Any ideas? I am on OS X 10.2.3 using the new BETA script editor.
First of all, you can stop it via command-. (command-period) which is like a
force-quit but maybe neater. If you think that users might try to use the
"Qui" item in the dock (which certainly appears to indicate that you can
quit, and seems to be a bug) then add a 'quit' handler, with just this in
it:
on quit
set quitNow to true
continue quit
end quit
At the top of you script declare a global variable (that is, if you have any
handlers)
global quitNow
set quitNow to false
and at the top of each iteration of the repeat loop add a way to quit:
repeat with i from 1 to whatever
if quitNow then error number -128
set something to item i of someList
--etc
end repeat
A 'quit' handler doesn't actually quit - it merely _intercepts_ any quit
event, such as selecting "Quit" in the dock or application menu, pressing
command-Q, or the script coming to its end. None of those (except the
natural end, of course, where it's not needed since you can just script
anything you need to do at the end of the script), are not supposed to be
possible in an non-stay-open applet. But, in OS X, for some reason they are.
So this can take care of it. 'error number -128' at the top of each repeat
loop will end the script immediately when it starts the next loop. You could
instead, call another handler which would take care of other things before
terminating, if you need to.
But, beware: do NOT use a quit handler if anywhere in your script you use
'store script'. I have discovered a bug that will empty your running script
into the file intended by 'store script' and does not save any changes in
the running script into its own file: the Lost Script bug. If you don't use
'store script', it's safe.
--
Paul Berkowitz
_______________________________________________
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.