Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 774
user2555399 Avatar asked Aug 22 '13 05:08

user2555399


2 Answers

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
like image 113
Michele Percich Avatar answered Oct 20 '22 17:10

Michele Percich


tell application "System Events"
    set processList to get the name of every process whose background only is false
    set processNameList to choose from list processList with prompt "Select process to quit" with multiple selections allowed
    if the result is not false then
        repeat with processName in processNameList
            do shell script "Killall " & quoted form of processName
        end repeat
    end if
end tell

enter image description here

like image 40
Parag Bafna Avatar answered Oct 20 '22 19:10

Parag Bafna