Выйти из всех приложений, используя Applescript? - PullRequest
12 голосов
/ 30 января 2009

Как мне выйти из всех запущенных пользовательских приложений, использующих Applescript?

Ответы [ 4 ]

10 голосов
/ 30 января 2009

Все в порядке ... Я думаю, что нашел свой ответ:

tell application "System Events" to set the visible of every process to true

set white_list to {"Finder"}

try
    tell application "Finder"
        set process_list to the name of every process whose visible is true
    end tell
    repeat with i from 1 to (number of items in process_list)
        set this_process to item i of the process_list
        if this_process is not in white_list then
            tell application this_process
                quit
            end tell
        end if
    end repeat
on error
    tell the current application to display dialog "An error has occurred!" & return & "This script will now quit" buttons {"Quit"} default button 1 with icon 0
end try
1 голос
/ 30 мая 2017

После некоторого поиска, я нашел лучший подход:

  • Он использует background only для создания начального списка приложений, а не visible is true. Разница в том, что другие сценарии потерпят неудачу выйти из приложения, которое было скрыто с помощью ⌘H.
  • Предоставляет исключения список, так что, например, вы можете предотвратить ваш редактор сценариев от выходить каждый раз, когда вы тестируете скрипт.

Адаптировано из ветки на MacScripter .

-- get list of open apps
tell application "System Events"
  set allApps to displayed name of (every process whose background only is false) as list
end tell

-- leave some apps open 
set exclusions to {"AppleScript Editor", "Automator", "Finder", "LaunchBar"}

-- quit each app
repeat with thisApp in allApps
  set thisApp to thisApp as text
  if thisApp is not in exclusions then
    tell application thisApp to quit
  end if
end repeat
1 голос
/ 04 марта 2017
tell application "System Events" to set the visible of every process to true

set white_list to {"Finder"}

try   
    tell application "Finder"   
        set process_list to the name of every process whose visible is true   
    end tell   
    repeat with i from 1 to (number of items in process_list)   
        set this_process to item i of the process_list   
        if this_process is not in white_list then   
            tell application this_process   
                quit   
            end tell   
        end if   
    end repeat   
on error   
    tell the current application to display dialog "An error has occurred!" & return & "This script will now quit" buttons {"Quit"} default button 1 with icon 0   
end try
0 голосов
/ 24 марта 2015
    tell application "System Events" to set quitapps to name of every application process whose visible is true and name is not "Finder"

repeat with closeall in quitapps

quit application closeall

end repeat
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...