macos - 如何使用 AppleScript 关闭 Safari 偏好设置窗口?
问题描述
我正在使用以下脚本来启用开发人员菜单。
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.
出错了。
还有如何仅在未启用时启用复选框?目前,如果我运行脚本两次,它会切换。
解决方案
此 AppleScript 代码适用于我使用最新版本的 macOS Mojave。
tell application "System Events"
tell application process "Safari"
set frontmost to true
end tell
keystroke "." using {command down}
end tell
推荐阅读
- javascript - 基于 Electron 的 XMLHttpRequest 和基于浏览器的带有查询字符串的 URL 之间的区别?
- angular - ngIf ExpressionChangedAfterItHasBeenCheckedError
- php - 自定义帖子类型循环:在 4 列中分组标题,在 1 列中直接在它们下方的 4 个帖子的内容
- go - 命令行应用程序输出使用说明,即使我认为我已经正确使用它
- java - 我如何使用来自firebase的数据制作recyclerview,并有意图地点击
- python - 我无法通过 Tweepy 收到直接消息
- c++ - 返回值部分且确定性地变化
- python - 有没有办法在 python 脚本中调用 python 子进程并将子进程的返回定向到脚本打开的文件?
- c# - App.xaml.cs 中的 Xamarin 表单更新值
- javascript - Chrome Web 扩展因“禁用开发者模式扩展”Chrome 弹出窗口而停止