获取AppleScript以单击“系统偏好设置”中的复选框

时间:2017-08-23 23:22:17

标签: macos applescript

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

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

谢谢!

3 个答案:

答案 0 :(得分:1)

此代码适用于最新版本的Sierra on MBP 15“

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"

速度:无评论 LOL

enter image description here

答案 1 :(得分:0)

我认为scroll area 1

这是一个稍微快一点的代码。它使用系统偏好设置套件中的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

答案 2 :(得分:0)

我带着同样的问题来到这里,但没有一个解决方案有效(对我来说) 这奏效了。

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 以用于远程登录
对于所有其他情况

谢谢