Search code examples
macosapplescriptosx-mountain-lion

Applescript get list of running apps?


Applescript newbie question again :) I am trying to create a small applescript that will allow me to select multiple items from a list of currently running applications and then quit those selected apps. Something like this works but rather than having to click on each dialog it would be much easier to chose from a list.

tell application "System Events"
repeat with p in every process
    if background only of p is false then
        display dialog "Would you like to quit " & name of p & "?" as string
    end if
end repeat
end tell

Any and all help would be greatly appreciated!

Thanks!


Solution

  • Try this:

    tell application "System Events"
        set listOfProcesses to (name of every process where background only is false)
        tell me to set selectedProcesses to choose from list listOfProcesses with multiple selections allowed
    end tell
    --The variable `selectedProcesses` will contain the list of selected items.
    repeat with processName in selectedProcesses
        do shell script "Killall " & quoted form of processName
    end repeat