Jump to content

[Request] Workflow to enable/disable Internet Sharing


Recommended Posts

My MacBook does not sleep while internet sharing is enabled. Therefore I usually go to system preferences to turn it off and on multiple times a day.

 

Can anybody help me with creating a workflow that completes this task faster? I'm a newbie for sure.

 

Thanks in advance!

Link to comment
Perfect! 

I had to change row 11 to row 9, and "Airport" to "Internet Sharing" in the Applescript. I think that's because this is an old lifehacker post and things have changed in OS X.

 
I also added this at the end:
tell application "System Preferences"
  quit
end tell
Link to comment

Could you help me change the Applescript so that it always turns Internet Sharing off? I want to add this script to the end of a different Workflow so that OS X always turns off Internet Sharing and goes to sleep:

tell application finder

  to sleep

end tell

Link to comment

I think you could add an if...then to only execute the click statement if the checkbox is checked.

 

Some guidance on how to do so is here: http://stackoverflow.com/questions/9690129/tick-a-checkbox-only-if-its-not-selected

 

& here: http://stackoverflow.com/questions/13021798/verify-a-checkbox-before-clicking-with-applescript

 

Your code is the post above would need to begin

tell application "Finder" (i.e. with the app name quoted).

Link to comment
  • 9 months later...

I am not sure why this applescript is not working correctly for me in Mavericks.  I really know nothing about Applescript, but I was using this for a long time to toggle internet sharing off and on via wifi.

 

Here is what happens.  If I run this without System Preferences open, it opens System Preferences and then stops.

If I have System Preferences open, it goes through and turns on Internet Sharing and "start" as well, but then after a moment, my wifi turns off.

 

This is quite puzzling.  It's probably a simple fix, but I do not know what to do.

 

Thanks.

 

on alfred_script(q)

 
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 2
    tell window "Sharing"
      click checkbox 1 of row 7 of table 1 of scroll area 1 of group 1
      delay 1
      if (exists sheet 1) then
        click button "Start" of sheet 1
      end if
    end tell
  end tell
end tell
 
tell application "System Preferences"
  quit
end tell
end alfred_script
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...