0

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!

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

4 Comments

You said, "This is a slightly faster code.", so where's the authoritative proof of that statement?
It's an statement based on my subjective observation. Based on your question, I tested OP's code and my code (in Script Debugger), and I'm getting: 2s and 1.97s, respectively. It's a very little difference.
Okay, but lets face it, unless you at the very least, closed Script Debugger and purged memory in between tests then those timings are really irrelevant.
Thanks, but I still run into the same issue. The code will run, but it still will not check the box. Could it be because my mac is managed by Jamf? I can manipulate other system prefs just fine though.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.