【发布时间】:2019-11-13 07:28:50
【问题描述】:
我正在尝试构建一个执行硬关机的脚本。相当于 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
这是我到目前为止所得到的;它几乎总是会导致错误。
提前感谢您的帮助。
【问题讨论】:
标签: macos shutdown automator macos-mojave