Any ideas why this script doesn't work?

Hi,

I’m trying to get my internet sharing to work with a simple script, but it keeps erroring after opening ‘System Preferences’. Can anyone help - here’s the script:

tell application “System Preferences”
activate
end tell

tell application “System Events”
tell process “System Preferences”
click menu item “Sharing” of menu “View” of menu bar 1
delay 10
tell window “Sharing”
if (exists tab group 1) then
tell tab group 1
click radio button “Internet”
delay 1
click button “Start”
delay 1
end tell
end if
end tell
end tell
end tell

ignoring application responses
tell application “System Preferences” to quit
end ignoring

All the best

Steve

Hi Steve,

It seems to stop on selecting the Sharing pane in System Preferences. Don’t know if this will help but you can get directly to the right pane with:

set current pane to pane “com.apple.preference.sharing”

after the first tell and before the activate.

Cheers

In OS X 10.3.8 I get there with this:

tell application "Finder"
     open alias "MyHD:System:Library:PreferencePanes:EnergySaver.prefPane:"
end tell

but I can’t get there with the method you quoted.

By the way, there’s some useful stuff further down this forum; it’s in “My 1st Script - System Prefs Checkbox - Please Help”

Cheers

try “com.apple.preferences.sharing” (plural preferences).

I deleted my previous post as I made a goof.

Thanks for the help, guys - I’m new to scripting, and based on what I’ve read today I now have a script that gets me to the Internet pane. Any idea how I get the start button to click?

The script up to now:

tell application “System Preferences”
activate
set current pane to pane “com.apple.preferences.sharing”
end tell

tell application “System Events”
tell application process “System Preferences”
tell window “sharing”
tell tab group 1
click radio button “Internet”
end tell
end tell
end tell
end tell

All the best

Steve

Based on the referenced other thread, I came up with this, which works as long as the “To Computers Using” table has the thing you want in the first row:


tell application "Finder" to open alias (((path to library folder from system domain) as text) & "PreferencePanes:SharingPref.PrefPane")
delay 0.5

tell application "System Events" to tell application process "System Preferences" to tell window 1
	tell tab group 1
		click radio button "Internet"
		click pop up button 1
		pick menu item "Built-in Ethernet" of menu of pop up button 1
		delay 0.5 --the menu item flashes 
		
		if value of checkbox 1 of row 1 of table 1 of scroll area 1 is 0 then
			select row 1 of table 1 of scroll area 1
			click checkbox 1 of row 1 of table 1 of scroll area 1
		end if
	end tell
	
	if exists sheet 1 then tell sheet 1 to click button "OK"
	
	tell tab group 1 to click button "Start"
	
	if exists sheet 1 then tell sheet 1 to click button "Start"
	
end tell