Domanda

I'm looking for something that I can use to kill all internet connections on my mac. Something that turns the wifi off, turns off the ethernet connections. Maybe an apple script or something. I tried using automator and using the Watch me Do, turning off the wifi and then making some changes to it's apple scipt, but that only works sometimes. I need something that will work every time, and good. Here's what I had in apple script, maybe someone smart can have a look and maybe remove the delay time altogether (I tried that, wouldnt' "compile")

on run {input, parameters}
-- Click the “Apple” menu.
delay 0.01
set timeoutSeconds to 0.0
set uiScript to "click menu bar item \"Apple\" of menu bar 1 of application process \"Finder\""
my doWithTimeout(uiScript, timeoutSeconds)

-- System Preferences…
delay 0.01
set timeoutSeconds to 0.01
set uiScript to "click menu item 4 of menu 1 of menu bar item \"Apple\" of menu bar 1 of application process \"Finder\""
my doWithTimeout(uiScript, timeoutSeconds)

-- Click the “Network” button.
delay 0.01
set timeoutSeconds to 0.01
set uiScript to "click UI Element \"Network\" of scroll area 1 of window \"System Preferences\" of application process \"System Preferences\""
my doWithTimeout(uiScript, timeoutSeconds)

-- Click the “Turn Wi-Fi Off” button.
delay 0.01
set timeoutSeconds to 0.01
set uiScript to "click UI Element \"Turn Wi-Fi Off\" of group 1 of window \"Network\" of application process \"System Preferences\""
my doWithTimeout(uiScript, timeoutSeconds)
return input

end run

on doWithTimeout(uiScript, timeoutSeconds)
    set endDate to (current date) + timeoutSeconds
    repeat
        try
            run script "tell application \"System Events\"
" & uiScript & "
end tell"
            exit repeat
        on error errorMessage
            if ((current date) > endDate) then
                error "Can not " & uiScript
            end if
        end try
    end repeat
end doWithTimeout

Thanks for your help!

È stato utile?

Soluzione

  1. Launch System Preferences

  2. Go to "Network" pane and click on "Location" dropdown:

enter image description here

  1. Choose "Edit Locations…" from the dropdown, and then the + in the small window which appears. This will create an "Untitled" location. I recommend renaming it to "Offline" or something similar. Click "Done"

enter image description here

  1. With the "Offline" location now active, select each connection/service in the left column (WiFi, Ethernet, etc). Then click the circle icon at the bottom of the left column and choose "Make Service Inactive" as shown below:

enter image description here

  1. After you have repeated that for each action, click "Apply" at the bottom-right of the window.

Once that is done, you can "kill" all of your network connections by switching to the "Offline" location, and re-enable them by switching back the "Automatic" location (or equivalent).

You can switch to that location by any number of methods. My preferred way would be to use a Keyboard Maestro macro, as Keyboard Maestro has a built-in feature to switch locations, and you can easily bind such a macro to a keyboard shortcut.

You could also do it with a shell script which ran

/usr/sbin/networksetup -switchtolocation 'Offline'

(Replace Offline with whatever you named your location.)

Note that many of /usr/sbin/networksetup's features require sudo but -switchtolocation does not.

To get back online, you would need to run /usr/sbin/networksetup -switchtolocation 'Automatic'

Or whatever your default location is called.

You can also quickly switch locations via "the  menu" which will add a "Locations" sub-menu once there is more than one location defined.

enter image description here

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a apple.stackexchange
scroll top