【问题标题】:How to close Safari preference window using AppleScript?如何使用 AppleScript 关闭 Safari 偏好设置窗口?
【发布时间】:2019-07-12 05:19:30
【问题描述】:

我正在使用下面的脚本来启用开发者菜单。

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. 错误。


只有在未启用的情况下,如何启用复选框?目前,如果我运行脚本两次,它会切换。

【问题讨论】:

    标签: macos applescript


    【解决方案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
    

    【讨论】:

      【解决方案2】:

      此 AppleScript 代码适用于我使用最新版本的 macOS Mojave。

      tell application "System Events"
          tell application process "Safari"
              set frontmost to true
          end tell
          keystroke "." using {command down}
      end tell
      

      【讨论】:

      • BTW ⌘. 还可以在 macOS High Sierra 上关闭 Safari 中的“首选项”窗口。
      猜你喜欢
      • 2016-09-15
      • 1970-01-01
      • 2012-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-28
      • 1970-01-01
      • 2018-09-22
      相关资源
      最近更新 更多