Now that I have a script compiled into xCode, something’s missing. The script editor had this lovely stop button that we could use to um, stop the script.
I’d never considered how to halt the script as it’s running now that it’s compiled into an app. Any ideas?
If the application that your working on is idle, you can also quit the app. Some app’s that you’re working on may need to be shutdown properly; those things that need to terminate, be saved, or closed, should be addressed when the application is quit.
Sorry Shane, I think you misunderstand. There is no red tasks button. There is no console. I’ve compiled the Applescript in xCode and when running as a standalone app, the script runs until it is done.
I’m hoping I don’t have to make the code callback enabled and timer serviced. It would be nice if something like a command period would stop the script (now an app) from executing, but that does not seem to be the case.
property myBoolean: false
on myEndButton_(sender)
set myBoolean to true ---Bind to a button in your app
end myEndButton_
on myScript_(sender)
if myBoolean is equal to true then return
-- do script stuff
-- do script stuff
etc etc etc
end myScript_
What’s the difference between compiling a plain AppleScript in ScriptEditor and press the Stop button
and compiling an AppleScript Studio script in Xcode and press the Tasks button.
Or the other way round: Can you stop a script saved as application in Script Editor and run as standalone app?
Eric - Thanks. It looks like that’s what I’m going to do. The trick is that once I click my start button, the applescript locks up the UI in the app, so I’ll have to break up the script into pieces that get called by a timer somehow so that one will only get called after another.
I wish I could just spawn a thread that does not lock up the UI and I could just issue a kill to that thread.
a good way to break a script like that is making a cocoa call…
“performSelector:withObject:afterDelay”
on scriptToBindToButton_(sender)
performSelector_withObject_afterDelay_("scriptChunkOne:",sender,0.0)
end
on scriptChunkOne_(sender)
tell me
do some stuff
end tell
performSelector_withObject_afterDelay_("scriptChunkTwo:",sender,0.0)
end scriptChunkOne_
on scriptChunkTwo_(sender)
tell me
do some stuff
end tell
performSelector_withObject_afterDelay_("scriptChunkThree:",sender,0.0)
end scriptChunkTwo
etc etc etc
Hmmm. Eric, the problem with what you suggested is that the performSelector_withObject_afterDelay_ command does not wait for the previous object to finish and since I have no idea how long the previous task will take to finish, I can’t specify a timeout.
-- Idle wrapper
on applicationWillFinishLaunching_(aNotification)
my performSelector_withObject_afterDelay_("idleWrapper", missing value, 0.01)
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
return true
end applicationShouldTerminate_
on idleWrapper()
try
-- The following calls the "on idle" handler and triggers
-- an error if that handler fails, or if it returns a
-- non-numeric value:
set idleTime to (0.0 + (idle))
on error
set idleTime to missing value
end try
if (idleTime is missing value) or (idleTime ≤ 0.0) then
set idleTime to 1.0 -- AppleScript default for idle handler delay in seconds
end if
my performSelector_withObject_afterDelay_("idleWrapper", missing value, idleTime)
end idleWrapper
----