mmusau
mmusau

Reputation: 1

Getting AppleScript to click checkbox in System Preferences

I have got what I think to be the correct code, but it doesn't seem to fully accomplish what I want. All I want is to get applescript to select a checkbox in the Sharing pane in system prefs. I'm not sure why it won't check the box, I have (to my knowledge) gotten the heirachy correct but there's nothing doing.

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

Thanks!

Upvotes: 0

Views: 2883

Answers (3)

Random Kindle
Random Kindle

Reputation: 520

I came here with the same issue but none of the solutions worked (For ME) This worked.

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

Change click checkbox 1 of row 1 to click checkbox 1 of row 2 to press File Sharing Checkbox
Change click checkbox 1 of row 1 to click checkbox 1 of row 5 for Remote Login
and Likewise for every other situation

Thank You

Upvotes: 0

wch1zpink
wch1zpink

Reputation: 3142

This code works for me on latest version of 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"

Speed: No Comment LOL

enter image description here

Upvotes: 1

unlocked2412
unlocked2412

Reputation: 121

I think it's scroll area 1.

This is a slightly faster code. It uses reveal action from System Preferences Suite. It then performs action "AXPress" to toggle checkbox 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

Upvotes: 0

Related Questions