This seems to work for me:
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 1 of row 1 of table 1 of scroll area 1 of group 1 of window "Sharing" to if value is 0 then click end tell tell process "System Preferences" delay 1 click button 1 of group 1 of window "Sharing" tell sheet 1 of window "Sharing" tell checkbox "VNC viewers may control screen with password:" to if value is 0 then click delay 1 set value of text field 1 to "p" click button "ok" end tell end tell end tell
Specifically the text field (and "VNC viewers..." checkbox and "OK" button" are members of tell sheet 1 of window "Sharing"
, so the tell
needs to be adjusted appropriately.
In case you don't know them, a couple of tools which make this sort of thing easier:
- The
Accessibility Inspector
is a little utility bundled in OSX (or perhaps its in xcode - not sure). It gives a lot of information about whatever UI element in any window that your mouse is currently over. entire contents of
allows you to dump all UI elements in a given scope when using the Applescript Editor. For example if I insertedget entire contents of window "Sharing"
in the appropriate place in this script, it would list out all UI elements of the window "sharing" in the events panel of the Applescript editor.