【问题标题】:How do I use applescript to get this checkmark clicked我如何使用applescript来点击这个复选标记
【发布时间】:2016-09-05 19:44:30
【问题描述】:

所以我想使用applescript单击系统偏好设置中“允许所有用户访问”的复选标记,然后共享然后远程登录。如本截图所示:

What it should look like if it works

无论如何,我已经非常接近能够点击它但我还没有成功这里是我到目前为止的脚本:

tell application "System Preferences"
set current pane to pane "com.apple.preferences.sharing"
end tell
tell application "System Events"
    tell process "System Preferences"
        tell checkbox 2 of row 4 of table 1 of scroll area 1 of group 1 of window "Sharing" to if value is 0 then click
    end tell
end tell

我只是无法点击正确的复选框,如果你们能帮助我,那就太棒了。谢谢!

(已解决)

【问题讨论】:

    标签: applescript


    【解决方案1】:

    你需要做2个步骤:

    1) 找到包含“远程登录”服务的正确行。这可能并不总是一个固定数字(即您的示例中的第 5 行)。然后选择该行并单击复选框以激活

    2) 服务激活后,点击“所有用户”单选按钮

    下面的脚本使用 cmets 执行此操作:

    set SWindow to "Sharing"
    set SRow to "Remote Login"
    
    tell application "System Preferences"
    set current pane to pane "com.apple.preferences.sharing"
    end tell
    tell application "System Events"
    tell process "System Preferences"
        -- get the correct row number of the sharing services
        repeat with theRow in every row of table 1 of scroll area 1 of group 1 of window SWindow
            if value of UI element 2 of theRow is SRow then -- this is the "Remote Login" row
                select theRow -- select the row
                if value of checkbox 1 of theRow is 0 then click checkbox of theRow -- click on activate check box if not yet set
            end if
        end repeat
        delay 1 -- time to display the correct pane with the users for sharing
        click radio button 1 of radio group 1 of group 1 of window SWindow -- click the button "all users"  
    end tell
    end tell
    

    注意:我定义并分配了 2 个变量 SWindow 和 SRow,因为我更容易用我的系统进行测试(不是英语,那么不同的字符串值!)。

    【讨论】:

    • 我遇到的主要问题之一是为按钮找到正确的名称,我不知道它被称为单选按钮,因此对将来的参考非常有用。谢谢!
    【解决方案2】:

    无需 GUI 脚本的智能解决方案(需要管理员密码):

    do shell script "launchctl load -w /System/Library/LaunchDaemons/ssh.plist" with administrator privileges
    do shell script "/usr/bin/dscl . -delete /Groups/com.apple.access_ssh" with administrator privileges
    

    警告dscl 行将“仅限这些用户”中创建的组完全删除。

    【讨论】:

    • 我一直在寻找一种无需管理员权限的方法,但无论如何感谢,知道多种做事方式总是很高兴。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多