Enable File Sharing through AppleScripts UI elements in System Preferences

I'm trying to write a script that will enable the File Sharing feature under the System Preferences Sharing pane. Here's what I've got so far:

tell application "System Preferences"
activate
reveal pane "Sharing"

tell application "System Events"
tell process "System Preferences"

click checkbox "File Sharing" of table "services" of scroll area 1 of tab group 1 of window "Sharing"

end tell
end tell

end tell

That brings the Sharing pane to focus, but then errors out and tells me the following:

System Events got an error: Can’t get tab group 1 of window "Sharing" of process "System Preferences". Invalid index.

I've tried every UI path I could find to get it to recognize the checkbox. I even downloaded and installed PreFab's UI Browser. It showed me a different path than the Accessibility Inspector did, but that wouldn't work either. It seems like no matter what path I put in, it can't find the checkbox!

I will also need (once I get this working) to find a way to have the Options button within the File Sharing section get pressed, but one thing at a time I guess...

Also, if anyone has any ideas on a simpler method of scripting this feature (e.g. Shell script, another AppleScript call, etc.), please let me know! Thanks for the help in advance!

Jesse

Message was edited by: wozwas

iMac 8,1, Mac OS X (10.6)

Posted on Oct 16, 2010 9:57 PM

Reply
7 replies

Oct 17, 2010 2:45 AM in response to wozwas

This works for me on 10.5.8

tell application "System Preferences"
activate
set current pane to pane "com.apple.preferences.sharing"
end tell
tell application "System Events"
tell process "System Preferences"
click checkbox 1 of row 3 of table 1 of scroll area 1 of group 1 of window "Sharing"
end tell
end tell


edit:
Saw you also needed to hit the button in the split box "options..." as well.
click button 3 of splitter group of group of window "Sharing"


Message was edited by: taylor.henderson

Oct 18, 2010 10:12 AM in response to wozwas

Also, if anyone has any ideas on a simpler method of scripting this feature (e.g. Shell script, another AppleScript call, etc.), please let me know! Thanks for the help in advance!


I can't think of a harder way than UI Scripting. I usually regard UI Scripting as the last resort.

Instead, consider something like:

do shell script "cd /System/Library/LaunchDaemons; launchctl load -w com.apple.AppleFileServer.plist" with administrator privileges

Oct 22, 2010 12:53 PM in response to wozwas

really appreciate the help. So that shell command will activate Sharing, but is there a method for activating File Sharing specifically, and then turning on SMB?


It wasn't clear that you wanted SMB. The command I listed was specifically for AFP.

For SMB it's just a matter of starting the SMB process:

do shell script "cd /System/Library/LaunchDaemons; launchctl load -w smbd.plist" with administrator privileges

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Enable File Sharing through AppleScripts UI elements in System Preferences

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.