Last active
April 16, 2019 10:40
-
-
Save almir/cc32de4fb017575246ff34e4d46c4d1a to your computer and use it in GitHub Desktop.
Disable Wi-Fi when LAN cable is plugged in and enable it when the cable is plugged out
This file contains 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 | |
IFACE="${1}" | |
ACTION="${2}" | |
ntfy () { | |
LOGGED_USERS=$(users) | |
for user in ${LOGGED_USERS} | |
do | |
USERID=$(id -u ${user}) | |
sudo -u ${user} \ | |
DISPLAY=:0 \ | |
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/${USERID}/bus \ | |
notify-send "${1}" "${2}" | |
done | |
} | |
case ${IFACE} in | |
eth*|usb*|en* ) | |
case ${ACTION} in | |
up ) | |
ntfy "Ethernet connected" "Disabling Wi-Fi" | |
nmcli radio wifi off | |
;; | |
down ) | |
ntfy "Ethernet disconnected" "Enabling Wi-Fi" | |
nmcli radio wifi on | |
;; | |
esac | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is based on https://gist.github.com/cengizIO/c9023b83a8590dd2c723f3181633c99a
The script should be placed under
/etc/NetworkManager/dispatcher.d/
with a name like99-disable-wireless-when-wired
.Make sure that it's owned by
root
and that it's executable (sudo chown root:root /etc/NetworkManager/dispatcher.d/99-disable-wireless-when-wired && sudo chmod +x /etc/NetworkManager/dispatcher.d/99-disable-wireless-when-wired
).Also,
NetworkManager-dispatcher
service should be enabled and running for this to work.