help needed to abort a script
help needed to abort a script
- Subject: help needed to abort a script
- From: Ken Victor <email@hidden>
- Date: Tue, 16 Jan 2001 18:02:05 -0800
i'm developing a build system using applescript and a bunch of plugin scripts.
the main application is basically something like:
property userAborted : false
script main
on run
set userAborted to false
repeat 4 times
if userAborted then exit repeat
set plugin to (load script file
"disk2:desktop folder:bs:test scripts:plugin")
tell plugin to doit(main)
tell application "Finder" to get folders of
startup disk
if userAborted then exit repeat
delay 2
end repeat
end run
end script
on MyDoDialog(dText)
display dialog ("My Do Dialog: '" & dText & "' .")
end MyDoDialog
on init()
activate
run main
tell me to quit
end init
on SetUserAborted()
tell me to display dialog ("about to send abort")
set userAborted to true
end SetUserAborted
this is a stay open application and in fact it is launched via
another script which actually passes some parameters into the init
handler which are used to drive the script. this stay open
application then loads successive compiled scripts from a known
location and executes them (these compiled scripts are what i call
plugins). (the above example simply repeats 4 times-- in reality, i
repeat over the files in my plugins folder.)
a simple plug in might be:
on doit(main)
MyDoDialog("my plug in" & ((current date) as string)) of main
end doit
(most plugins will do something significant, not just display a
dialog.) note that i pass the main script object as a parameter to
the plugins -- this gives the plugins access to the handlers in the
main script.
basically, i have this working. the problem i'm having is in aborting
the process if i realize that it should be aborted.
i have a separate non stay open application that looks like:
tell application "MyStayOpenApp" to SetUserAborted()
my understanding says that if i double click this aborter at the
finder it should then send an apple event to my stay open app and my
stay open app should receive this message and act upon it and then
resume whatever it was doing.
but this isn't happening reliably. whether or not the
SetUserAborted() handler gets invoked seems to be dependent on what
the plugins and the rest of the stay open app do. ie, in some trivial
cases, i've been able to get this to work; but most of the time, the
SetUserAborted() handler isn't invoked until the last message sent to
the stay open app has completed!
do i have some misunderstanding? note that i'm running on a dual
processor g4/500 with plenty of ram with os 9.0.4 and applescript
1.4.3 and carbon lib 1.0.4.
(i even purchased script debugger to try to figure out what was going
on, but i guess i'm going to have to read the manual, as i haven't
been able to successfully debug my stay open app with it..)
note that previously my abort script would simply create a file in a
known location and my stay open app would just periodically use the
finder to see if that file exists, and if so, then it would consider
that the user had aborted. unfortunately, this added significant and
unacceptable execution time to the scripts.
so... what is the best way to abort a script?
thanx,
ken