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
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
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