Applescript get list of running apps?

旧时模样 提交于 2019-12-03 06:13:23

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
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

you can use this script which is much simpler

tell application "Finder"
    get the name of every process whose visible is true
end tell

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
James

& (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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!