fake666666666 fake666666666 - 2 months ago 6
AppleScript Question

How do I use applescript to get this checkmark clicked

So I would like to use applescript to click the checkmark that says "allow access for all users" in System Preferences then sharing then remote login. As shown in this screenshot:

What it should look like if it works

Anyways so I've gotten really close to being able to get it clicked but i haven't yet succeeded here is the script that I have so far:

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


I just cant quite get it to click the right checkbox, if you guys could help me out that would be awesome. thanks!

(SOLVED)

Answer

You need to do 2 steps :

1) find the correct row containing the "Remote Login" service. This may not be always a fix number (i.e. row 5 in your example). then select the row and click the check box to activate

2) once the service is activated, click of the "all users" radio button

The script bellow does this with comments :

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

Note : I defined and assigned 2 variables SWindow and SRow because it is easier for me to test with my system (not English language, then not same string values !).