Hi, I made a small program and I need a shell script to be run when the user quits the program.
Any ideas?
on quit
display alert "Do something."
end quit
If it’s a Studio app, you also have these handlers available to you:
on should quit
on should quit after last window closed
on will quit
How about:
on quit
do stuff
continue quit
end quit
Ok, I tried this but it doesn’t seem to be working.
Here is all of my code:
on clicked theObject
if theObject is button "Start" of window "Window" then
set serverName to content of text field "servername" of window "Window"
set adminPass to content of text field "adminpass" of window "Window"
set serverPassword to content of text field "serverpassword" of window "Window"
set botsTrue to state of button "bots" of window "Window"
set statsTrue to state of button "stats" of window "Window"
set serverPass to state of button "serverpass" of window "Window"
set shellScript to "/Applications/Zap\\!\\ Folder/ZAP.app/Contents/MacOS/ZAP -dedicated -hostname " & serverName
set shellScript to shellScript & " -adminpassword "
set shellScript to shellScript & adminPass
if botsTrue = 1 then set shellScript to shellScript & " -bots"
if statsTrue = 1 then set shellScript to shellScript & " -stats"
if serverPass = 1 then set shellScript to shellScript & " -password "
if serverPass = 1 then set shellScript to shellScript & serverPassword
set shellScript to (shellScript & " &> /dev/null &")
do shell script shellScript
else if theObject is button "kill" of window "Window" then
do shell script "killall \"ZAP\""
end if
end clicked
on quit
do shell script "killall \"ZAP\""
continue quit
end quit
Hi,
Can you try something like this at the very end of your script? BTW, why do have two lines of do shell script doing the same thing?
else if theObject is button "kill" of window "Window" then
my quitButDoShell ()
end if
end clicked
on quitButDoShell ()
do shell script "killall \"ZAP\""
quit me
continue quit
end quitButDoShell
Good luck!
archseed
Hmm, nope didn’t seem to work?
The reason I had two shell scripts that did the same thing was one for pressing stop and one that was supposed to stop it on quit.
Hi cheese,
As Mikey-San said, you need to connect either the ‘should quit’ or ‘will quit’ handler to your Application object. To continue quit ‘return true’. ‘will quit’ always continues quitting.
gl,
Hi,
Sorry, it didn’t work.
For info, the reason why I suggested an outside quit handler to quit is - I don’t find the different quit handlers, as mikey-san listed, in my Xcode 2.2. There is no such thing there as “should quit, will quit or should quit after last window closed”. The outside handler was the only way I could make my app quit properly…at least the way it is right now.
What could be happening here? Is there another implementation of “quit” in 2.2 or is there something wrong with my copy?
Sorry cheese. I hope I am not diverting the issue away from yours but they are related.
Would appreciate some feedback. TIA.
archseed
Hi archseed,
In Interface Builder, in the nib window, did you select the Application icon. Then in the info window’s AppleScript pane, the quit handlers should be listed under the application event handlers. I’m using xcode, but think it’s still about the same.
gl,
Hi,
Thanks Kel.
I was looking for it in my main window which was obviously the wrong place. On further “snooping” around, I finally saw the quit handlers in the “File’s Owner” in the nib.
I should be able to fix my app now using one of true quit handlers (not my “custom” quit handlers, if you can call it that).
More power to you!
archseed