[AppleScript] Check what application is running in the foreground

Discussion in 'Mac Programming' started by Amad3U5, Jan 27, 2013.

  1. macrumors member

    Joined:
    Nov 17, 2012
    Location:
    Sydney
    #1
    I want to write an AppleScript that will force-quit the application running in the fore-ground (i.e the application in the status bar).

    How can I use AppleScript to determine what that application is?
     
  2. macrumors member

    Joined:
    Jun 23, 2009
    #2
    Code:
    tell application "System Events"
    	processes whose frontmost is true
    end
     
  3. macrumors member

    Mark FX

    Joined:
    Nov 18, 2011
    #3
    Just expanding on what bumper314 has posted.

    Code:
    tell application "System Events"
    	set frontmostApp to name of application processes whose frontmost is true
    	tell application frontmostApp
    		quit
    	end tell
    end tell
    
    This wont work in Applescript Editor, as Applescript editor will be the fronmost app, and will still be processing and running the script, so will only work when the script is compiled.

    Regards Mark
     

Share This Page