Альтернатива команде 'quit' - PullRequest
1 голос
/ 09 августа 2011

Я знаю, что заголовок вопроса выглядит странно, поэтому я попытаюсь объяснить его лучше: я знаю, что вы можете заставить приложения закрываться, выполнив следующее:

tell application "whatever" to quit

Я хочу знать, есть ли альтернативыделаем это.

Заранее спасибо.

Ответы [ 3 ]

1 голос
/ 09 августа 2011

Проблема с подходом tell application "whatever" to quit заключается в том, что вы можете ориентироваться только на приложения, которые установлены на вашем компьютере, после компиляции скрипта. Вот AppleScript, который определяет имена всех запущенных процессов приложения, а затем завершает каждый из них, отправляя ему команду quit.

property pExcludeApps : {"Finder", name of current application}

tell application "System Events"
    set theAppsToQuit to name of every process where background only = false
end tell

repeat with theApp in theAppsToQuit
    if pExcludeApps does not contain contents of theApp then
        tell application (contents of theApp)
            quit saving yes
        end tell
    end if
end repeat
1 голос
/ 13 августа 2011
delay 5
tell application (path to frontmost application as text) to quit saving no

delay 5
tell application "System Events" to set pid to unix id of (process 1 where frontmost is true)
do shell script "kill " & pid

tell application "TextEdit" to close windows
tell application "System Events" to tell process "TextEdit" to set visible to false
-- Lion will auto-terminate the app
1 голос
/ 09 августа 2011

Вы можете использовать GUI Scripting вот так ...

tell application "System Events" to tell process "whatever" to keystroke "q" using {command down}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...