Last active
August 29, 2015 14:05
-
-
Save eduo/b8fdc7a79e28d6a27a57 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#Verify your interfaces using "ifconfig" and disconnecting/reconnecting WiFi and Ethernet to find out which is which | |
# Works in mountain lion. Might need changes in DETECT_INET in other versions | |
# Default sound name "PC 3270 Beep" doesn't exist in standard installs. Sound name should be the file name, | |
# without extension, of .aif file placed in either /System/Library/Sounds or ~/Library/Sounds | |
# In this case I have /Users/eduo/Library/Sounds/PC 3270 Beep.aiff so name is "PC 3270B Beep" | |
# Remember to set permissions to execute on this script: chmod 755 WiFiOrEth.sh | |
ENET_INTERFACE="en2" | |
WLAN_INTERFACE="en0" | |
DETECT_ENET=$(ifconfig $ENET_INTERFACE 2>/dev/null| grep "status:" | tr -d '\t' | cut -d ' ' -f2 | tr -d '\n') | |
DETECT_WLAN=$(ifconfig $WLAN_INTERFACE 2>/dev/null| grep "status:" | tr -d '\t' | cut -d ' ' -f2 | tr -d '\n') | |
TITLE="Airport status changed" | |
SUBTITLE="${0}" | |
NOTIF="Airport as been modified due to Ethernet Status" | |
if [ "$DETECT_ENET" = "active" ] ; then | |
/usr/sbin/networksetup -setairportpower $WLAN_INTERFACE off | |
echo "$0 - Wired ethernet detected, turning off Airport." | |
TITLE="Airport Off" | |
NOTIF="Ethernet detected, Airport has been turned off" | |
osascript -e 'display notification "'"${NOTIF}"'" with title "'"${TITLE}"'" subtitle "'"${SUBTITLE}"'" sound name "PC 3270 Beep"' | |
exit 0 | |
elif [ "$DETECT_WLAN" = "inactive" ] ; then | |
/usr/sbin/networksetup -setairportpower $WLAN_INTERFACE on | |
echo "$0 - No wired ethernet, turning on Airport." | |
TITLE="Airport On" | |
NOTIF="Ethernet disconnected, Airport has been turned on" | |
osascript -e 'display notification "'"${NOTIF}"'" with title "'"${TITLE}"'" subtitle "'"${SUBTITLE}"'" sound name "PC 3270 Beep"' | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment