【问题标题】:Getting AppleScript to click checkbox in System Preferences让 AppleScript 单击系统偏好设置中的复选框
【发布时间】:2017-08-23 23:22:16
【问题描述】:

我得到了我认为正确的代码,但它似乎并没有完全实现我想要的。我想要的只是让applescript在系统首选项的“共享”窗格中选择一个复选框。我不确定为什么它不会选中该框,我(据我所知)得到了正确的继承权,但什么也没做。

tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preferences.sharing"
end tell

delay 2

tell application "System Events" to tell process "System Preferences"
 click checkbox 1 of row 1 of table 1 of scroll area of group 1 of window 
 "Sharing"
end tell

谢谢!

【问题讨论】:

    标签: macos applescript


    【解决方案1】:

    此代码适用于我在 MBP 15 上最新版本的 Sierra 上

    tell application "System Preferences"
        if it is running then
            quit
            delay 0.2
        end if
    end tell
    tell application "System Preferences" to reveal pane id "com.apple.preferences.sharing"
    tell application "System Events" to tell process "System Preferences"
        click checkbox 1 of row 1 of table 1 of scroll area 1 of group 1 of window 1
    end tell
    quit application "System Preferences"
    

    速度:无评论哈哈

    【讨论】:

      【解决方案2】:

      我想是scroll area 1

      这是一个稍微快一点的代码。它使用 System Preferences Suite 中的 reveal 操作。然后它执行“AXPress”动作来切换复选框 1。

      tell application "System Preferences"
          activate
          reveal pane id "com.apple.preferences.sharing"
          delay 1
      end tell
      
      tell application "System Events"
          tell process "System Preferences"
              tell checkbox 1 of row 1 of table 1 of scroll area 1 of group 1 of window 1
                  perform action "AXPress"
              end tell
          end tell
      end tell
      

      【讨论】:

      • 你说,“这是一个稍微快一点的代码。”,那么这个说法的权威证明在哪里?
      • 这是基于我的主观观察的陈述。根据您的问题,我测试了 OP 的代码和我的代码(在 Script Debugger 中),我分别得到:2s 和 1.97s。这是一个非常很小的区别。
      • 好的,但让我们面对现实吧,除非您至少在测试之间关闭脚本调试器并清除内存,否则这些时间真的无关紧要。
      • 谢谢,但我仍然遇到同样的问题。代码将运行,但仍不会选中该框。可能是因为我的 mac 是由 Jamf 管理的吗?不过,我可以很好地操作其他系统首选项。
      【解决方案3】:

      我带着同样的问题来到这里,但没有一个解决方案有效(对于我) 这行得通。

      tell application "System Preferences"
          activate
          set the current pane to pane id "com.apple.preferences.sharing"
      end tell
      
      delay 2
      
      tell application "System Events"
          tell process "System Preferences"
              click checkbox 1 of row 1 of table 1 of scroll area 1 of group 1 of window "Sharing" of application process "System Preferences" of application "System Events"
          end tell
      end tell
      

      click checkbox 1 of row 1更改为click checkbox 1 of row 2以按文件共享复选框
      click checkbox 1 of row 1 更改为 click checkbox 1 of row 5 以用于远程登录
      对于所有其他情况也是如此

      谢谢

      【讨论】:

        猜你喜欢
        • 2016-09-15
        • 2021-10-15
        • 1970-01-01
        • 2021-05-28
        • 2016-05-12
        • 1970-01-01
        • 2021-08-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多