View Full Version : Applescript on quit

Oct 18, 2009, 03:29 PM
How can I make it so that snow leopard executes and applescript when a certain application quits

Oct 18, 2009, 03:33 PM
To the best of my knowledge there is no way to do it. You could write your own background app that monitors for app startup and stop and the calls an AppleScript when an app dies. But if your code is not already running I don't see how you would receive the notification of app shutdown.

Oct 18, 2009, 03:48 PM
ok thanks for the information. I just thought that the OS had the option of executing a script on application quit.

Oct 18, 2009, 03:49 PM
Unless the specific application provides some mechanism to do that I don't think so (and a Google search gives no indication of an OS mechanism to do it that I was not aware of).

Oct 18, 2009, 05:20 PM
You could create a script that launches the app and then tells your monitor script to start waiting for the app to quit, then when it does, the monitor script can call your quit script.

If you give the first script the same icon as your app, you can put that in the dock and the process begins transparently.


Oct 20, 2009, 11:18 PM
here is some sample code for this

on idle

tell application "System Events" to
set exists_ to exists process "PandoraBoy"

if exists_ is false then
tell application "Airfoil"
end tell
quit me
end if

set timercount to timercount + 1
return 10 -- checks every 10 seconds to see if app has been quit

end idle

to make it not open in the dock

save the script as an application bundle. (Make sure to deselect "Startup Screen" then right click -> show package contents -> Info.plist add item "Appliction is background only" and check selected.