如何使用applescript来点击此复选标记

时间:2016-09-05 19:44:31

标签: applescript

所以我想使用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

我只是不能点击右边的复选框,如果你们可以帮助我那将是非常棒的。谢谢!

(解决)

2 个答案:

答案 0 :(得分:0)

您需要执行两个步骤:

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

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

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

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,因为我更容易使用我的系统进行测试(不是英语,不是相同的字符串值!)。

答案 1 :(得分:0)

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

$ cat test.txt
1,2,3,get me
4,5,,skip me
6,7,8,get me
9,10,11,stop before me
$ awk -F, '$3!="" && ++i<=2' test.txt
1,2,3,get me
6,7,8,get me

警告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 行完全删除“仅限这些用户”中创建的群组。