If you need an idle handler, maybe have experienced users, that know how to force quit, and something to clean up before you quit, then you need something like this: MacScripter / properties reset
[applescriptglobal shouldQuit
global didCleanup
on run
set shouldQuit to false
set didCleanup to false
try
– lengthy operation goes here
repeat with x from 1 to 10
if shouldQuit then error
say (x as string)
delay 5
end repeat
on error
tell me to quit
end try
end run
on quit
if not didCleanup then
– cleanup operation goes here
say “cleaning up”
set didCleanup to true
end if
set shouldQuit to true
continue quit
end quit