Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.8: Automate Internet Sharing revisited' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.8: Automate Internet Sharing revisited
Authored by: jpbrockway on Aug 29, '12 06:16:06PM

Thank you for the Apple Script. I have added to it so that if the "Internet Sharing" checkbox is already checked, it will uncheck it first.


# Open System Preferences application
tell application "System Preferences"
activate
end tell

# Open the Sharing preference pane
tell application "System Preferences"
reveal (pane id "com.apple.preferences.sharing")
end tell

# Select the Internet Sharing checkbox.
tell application "System Events"
tell process "System Preferences"
tell window "Sharing"
# Internet Sharing is row 8 in Mountain Lion.
set _checkbox to checkbox 1 of row 8 of table 1 of scroll area 1 of group 1
#set _checkbox to checkbox "Bluetooth Sharing" of table 1 of scroll area 1 of group 1

tell _checkbox
# If the checkbox is checked then uncheck.
if (its value as boolean) then click _checkbox
delay 1

# Recheck the checkbox.
click _checkbox
delay 1
end tell
if (exists sheet 1) then
if (exists button "Turn Wi-Fi On" of sheet 1) then
click button "Turn Wi-Fi On" of sheet 1
delay 1
end if
click button "Start" of sheet 1
end if
end tell
end tell
end tell

# Close System Preferences application
tell application "System Preferences"
quit
end tell



[ Reply to This | # ]