Устранение неполадок в сценарии жесткого отключения macOS с помощью автоматического - PullRequest
0 голосов
/ 02 июля 2019

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

tell application "System Events" to set the visible of every process to true   
set white_list to {"Finder", "Automator"}
try    
    tell application "Finder"    
        set process_list to the name of every process whose visible is true    
    end tell    
    repeat with theProcessName in process_list    
        tell application "System Events"    
            set theId to (unix id of every process whose name is theProcessName)    
            do shell script "kill -9 " & theId    
        end tell    
    end repeat    
    tell application "System Events" to shut down    
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 Ответ

0 голосов
/ 02 июля 2019

Сценарий не выполняется, поскольку строка

set theId to (unix id of every process whose name is theProcessName)

возвращает список (несколько элементов).Замените его на

set theId to unix id of process theProcessName

Предложение whose является избыточным, поскольку вы уже получили правильное имя процесса.

Примечание:

Для целей отладки настоятельно рекомендуется напечататьошибка

on error e   
    tell the current application to display dialog "The error '" & e & "' has occurred!" & return & "This script will now quit" buttons {"Quit"} default button 1 with icon 0    
end try
...