Last active
November 14, 2023 22:07
-
-
Save mnl/9cc38d120c5141e264d0a3049d8f4ba2 to your computer and use it in GitHub Desktop.
NetworkManager dispatcher script for wifi toggling
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 | |
# NetworkManager dispatcher script for /etc/NetworkManager/dispatcher.d/ | |
# Turn off wifi only while ethernet has connection. Adapted from manpage. | |
# mnl@vandal.nu 2023 | |
ethernet_connected() { | |
# Check if any ethernet connections are up | |
nmcli --terse --fields type,state device | while read -r | |
do | |
[ "${REPLY}" = ethernet:connected ] && return | |
done | |
} | |
conditionally_toggle_wifi() { | |
if ethernet_connected | |
then | |
nmcli radio wifi off | |
else | |
nmcli radio wifi on | |
fi | |
} | |
case ${NM_DISPATCHER_ACTION} in | |
up|down) | |
conditionally_toggle_wifi ;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment