我正在使用以下脚本启用开发人员菜单。
tell application "Safari"
tell application "System Events"
tell process "Safari"
click menu item "Preferences…" of menu 1 of menu bar item "Safari" of menu bar 1
click button "Advanced" of toolbar 1 of window 1
click checkbox "Show Develop menu in menu bar" of group 1 of group 1 of window 1
-- delay 2
keystroke "w" using {command down} -- > not working
end tell
end tell
end tell
如何关闭首选项窗口?使用keystroke "w" using {command down}
,我不会出现The document cannot be closed while the script is running.
错误。
也仅在未启用复选框的情况下如何启用它?当前,如果我运行脚本两次,它将切换。
答案 0 :(得分:1)
只需单击第一个窗口的第一个按钮,然后选中复选框value
tell application "Safari"
tell application "System Events"
tell process "Safari"
click menu item "Preferences…" of menu 1 of menu bar item "Safari" of menu bar 1
click button "Advanced" of toolbar 1 of window 1
tell checkbox "Show Develop menu in menu bar" of group 1 of group 1 of window 1
if value is 0 then click it
end tell
click button 1 of window 1
end tell
end tell
end tell
答案 1 :(得分:1)
此AppleScript代码适用于使用最新版本的macOS Mojave的我。
tell application "System Events"
tell application process "Safari"
set frontmost to true
end tell
keystroke "." using {command down}
end tell