我正在尝试编写一个苹果脚本来关闭所有打开的Windows。以下是我尝试的内容:
tell application "System Events"
repeat with theProcess in (application processes where visible is true)
tell application theProcess
close
end tell
end repeat
end tell
这似乎不起作用。我明白了:
脚本错误:系统事件出错:无法获取应用程序(每个应用程序进程的第1项,其visible = true)。号码-1728
如果应用程序退出或者窗口关闭,我不在乎。
我试着调试这个,但我无法在Xcode中打开这个脚本。
编辑:感谢user3439894我已经确定了以下脚本,它只是发送Command + Q
到每个可见的应用程序:
tell application "System Events"
set theVisibleApps to (name of application processes where visible is true)
end tell
repeat with thisApp in theVisibleApps
try
tell application thisApp to activate
tell application "System Events"
keystroke "q" using command down
end tell
on error errMsg
display dialog errMsg
end try
end repeat
这对我来说现在很有用。正如user3439894建议的那样,我需要了解AppleScript语言指南
{ApplicationName} got an error: every document does not understand the "close" message.
无论如何做某事click button 1 of window 1
或者按Ctrl + W或Ctrl + Q发送每个窗口?