Applescript get list of running apps?

2020-06-02 06:50发布

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!

5条回答
手持菜刀,她持情操
2楼-- · 2020-06-02 07:25

& (name of every process whose (name is "AppName") can be added to Michele Percich's and Parag Bafna's solutions to include specific menu bar applications by name.

tell application processName to quit can be used instead of do shell script "Killall " & quoted form of processName.

tell application "System Events"
    set processList to ¬
        (name of every process where background only is false) & ¬
        (name of every process whose ¬
            (name is "AppName") or ¬
            (name is "AnotherAppName"))
    tell me to set selectedProcesses to choose from list processList with prompt "Select process(es) to quit:" with multiple selections allowed
end tell
if the result is not false then
    repeat with processName in selectedProcesses
         tell application processName to quit
    end repeat
end if
查看更多
走好不送
3楼-- · 2020-06-02 07:29

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
查看更多
虎瘦雄心在
4楼-- · 2020-06-02 07:35

you can use this script which is much simpler

tell application "Finder"
    get the name of every process whose visible is true
end tell
查看更多
forever°为你锁心
5楼-- · 2020-06-02 07:40
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

查看更多
Ridiculous、
6楼-- · 2020-06-02 07:44

You can try this

tell application "System Events"
        set AppName to name of every process whose background only is false
        choose from list AppName OK button name "Ok" cancel button name "Cancel"
    end
查看更多
登录 后发表回答