Start/stop internet sharing from a manuscript?

Exists a means to start/stop internet sharing from the command line or possibly an apple manuscript?

Things is that I walk around my laptop computer in between residence and also job. At one area I get cordless net (and also hence I need to disable internet sharing), and also at the various other I get internet from an ethernet wire and also set up the computer system to share the net to various other tools by developing a tiny cordless network.

Yet it's obtaining a little bit laborious needing to go right into System Preferences and also start/stop the internet sharing every single time I switch over areas, so I would love to have a fast command or manuscript to release and also do the activate need.

Any kind of tips or suggestions?

0
2019-05-09 11:18:14
Source Share
Answers: 6

Slightly various than the various other applescript uploaded (I assume in a far better means yet). Having alternatives occasionally can aid.

 tell application "System Preferences"
   activate
   reveal (pane id "com.apple.preferences.sharing")
 end tell

 tell application "System Events"
   tell process "System Preferences"
     try
       click checkbox of row 11 of table 1 of scroll area of group 1 of window "Sharing"

       if checkbox of row 11 of table 1 of scroll area of group 1 of window "Sharing" is equal to 1 then
         repeat until sheet of window 1 exists
           delay 0.5
         end repeat
       end if

       if (sheet of window 1 exists) then
         click button "Start" of sheet of window 1
       end if

       tell application "System Preferences" to quit
       activate (display dialog "Internet Sharing preferences sucessfully flipped")

     on error     
       activate
       display dialog "something went wrong in automation but you are probably in the right menu…"
       return false
     end try
   end tell
 end tell
0
2019-05-21 00:03:55
Source

I took a sign from mankoff is solution and also covered it up in an AppleScript. I'm utilizing this manuscript from Automator to make sure that I can conveniently utilize it as a solution and also offer it a key-board faster way.

Toggle Internet Sharing:

register_growl()

try
    if isRunning("InternetSharing") then
        do shell script "launchctl unload -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist" with administrator privileges

        if isRunning("InternetSharing") then
            error "Internet Connection Sharing was Not Disabled"
        else
            my growlnote("Success", "Internet Connection Sharing Disabled")
        end if

    else
        do shell script "launchctl load -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist" with administrator privileges

        if isRunning("InternetSharing") then
            my growlnote("Success", "Internet Connection Sharing Enabled")
        else
            error "Internet Connection Sharing was Not Enabled"
        end if

    end if

on error errMsg
    my growlnote("Error", errMsg)

end try

on isRunning(processName)
    try
        return 0 < length of (do shell script "ps ax | grep -v grep | grep " & processName)
    on error
        return false
    end try
end isRunning

on register_growl()
    try
        tell application "GrowlHelperApp"
            set the notificationsList to {"Success", "Warning", "Error"}
            register as application "Toggle Internet Connection Sharing" all notifications notificationsList default notifications notificationsList icon of application "Sharing"
        end tell
    end try
end register_growl

on growlnote(growltype, str)
    try
        tell application "GrowlHelperApp"
            notify with name growltype title growltype description str application name "Toggle Internet Connection Sharing"
        end tell
    end try
end growlnote
0
2019-05-13 14:15:52
Source

To start Internet Sharing from the CLI :

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist

To stop, transform the load to unload .

Keep in mind that if you have the pref pane open when you run this you will certainly not see the adjustment work quickly (the UI will not upgrade), yet it does function.

0
2019-05-10 15:35:55
Source

The actually very easy means to do it is to incorporate @Philip's answer with the NetworkLocation application. NL can inform where you are, and also instantly run an AppleScript when it detects you've transformed areas.

I assume it's called for software program if you have a laptop computer-- or else, it's a PITA to constantly need to by hand reset numerous setups whenever I transform areas.

0
2019-05-10 15:21:55
Source

One means of doing this is by GUI scripting-- System Preferences does not have any kind of Applescript assistance by default.

tell application "System Preferences" to set current pane to pane "com.apple.preferences.sharing"
delay 1
tell application "System Events" to tell process "System Preferences"
    click checkbox 1 of row 8 of table 1 of scroll area 1 of group 1 of window "Sharing" -- change to row 10 if you are using anything before Snow Leopard
    delay 1
    if (exists sheet 1 of window "Sharing") then
        click button "Start" of sheet 1 of window "Sharing"
    end if
end tell
ignoring application responses
    tell application "System Preferences" to quit
end ignoring
0
2019-05-10 06:18:01
Source

You could intend to have a look at this (perhaps off subject for Stack Overflow) inquiry and also its solution : How to start/stop Internet Sharing using AppleScript.

do shell script "/bin/launchctl load -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist" with administrator privileges
0
2019-05-10 05:53:26
Source