Skip to content

Instantly share code, notes, and snippets.

@mbierman
Last active December 20, 2015 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbierman/6117583 to your computer and use it in GitHub Desktop.
Save mbierman/6117583 to your computer and use it in GitHub Desktop.
Turn off Wifi if Display Ethernet is plugged in
-- note this assumes your wireless ethernet interface is en1
-- get the correct interface from the menu Apple|About This Mac|Network|Wi-Fi or from terminal using ifconfig -a
-- todo:
-- dynamically set the wifi
--
set makiaeawireedstatus to null
set makiaeawireedstatus to do shell script "networksetup -listallhardwareports"
try
set makiaeawirelessstatus to do shell script "networksetup -getairportpower en0"
on error
display dialog "The script did not work as intended, please check the networksetup command (in terminal) works on your system. It has been tested on mac os 10.7 (Build 11A459e). Other versions of mac os may not have this command available. Please open the applescript in applescript editor for more details." buttons {"kthxbai"}
end try
-- Check to see if you have display Ethernet plugged in
if makiaeawireedstatus contains "Display Ethernet" then
-- display dialog "the string is:" & makiaeawireedstatus
if makiaeawirelessstatus is "Wi-Fi Power (en0): On" then
-- disable wifi
do shell script "networksetup -setairportpower en0 off"
end if
else
-- display dialog "nuttin' honey"
--if no display ethernet, turn on wifi
if makiaeawirelessstatus is "Wi-Fi Power (en0): Off" then
do shell script "networksetup -setairportpower en0 on"
end if
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment