Applescript on quit

Discussion in 'Mac Programming' started by talguy, Oct 18, 2009.

  1. macrumors member

    Joined:
    Jun 17, 2009
    #1
    How can I make it so that snow leopard executes and applescript when a certain application quits
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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.
     
  3. thread starter macrumors member

    Joined:
    Jun 17, 2009
    #3
    ok thanks for the information. I just thought that the OS had the option of executing a script on application quit.
     
  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    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).
     
  5. macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #5
    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.

    mt
     
  6. macrumors newbie

    Joined:
    Oct 20, 2009
    #6
    here is some sample code for this

    Code:
    on idle
    	
    	
    	tell application "System Events" to ¬
    		set exists_ to exists process "PandoraBoy"
    	
    	if exists_ is false then
    		tell application "Airfoil"
    			quit
    		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.
     

Share This Page