Created
May 8, 2020 12:57
-
-
Save eduo/cd5299713a7d9406c72d3b4da881bac3 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"' | |
osascript -e 'display notification "'"${NOTIF}"'" with title "'"${TITLE}"'" subtitle "'"${SUBTITLE}"'"' | |
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"' | |
osascript -e 'display notification "'"${NOTIF}"'" with title "'"${TITLE}"'" subtitle "'"${SUBTITLE}"'"¬' | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment