Applescript get list of running apps?

user2555399 picture user2555399 · Aug 22, 2013 · Viewed 11.2k times · Source

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!

Answer

Michele Percich picture Michele Percich · Aug 22, 2013

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