Skip to content

Instantly share code, notes, and snippets.

@cengiz-io
Last active October 9, 2023 16:36
Show Gist options
  • Save cengiz-io/c9023b83a8590dd2c723f3181633c99a to your computer and use it in GitHub Desktop.
Save cengiz-io/c9023b83a8590dd2c723f3181633c99a to your computer and use it in GitHub Desktop.
Script should be placed under `/etc/NetworkManager/dispatcher.d/` with a name like `99-disable-wireless-when-wired`. Make sure 1) root owns it 2) it's mod is 755
#!/bin/sh
IFACE=$1
ACTION=$2
ntfy () {
sudo -u cengiz \
DISPLAY=:0 \
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus \
notify-send "$1" "$2"
}
case ${IFACE} in
eth*|usb*|en*)
case ${ACTION} in
up)
ntfy "Ethernet connected" "Disabling Wifi"
nmcli radio wifi off
;;
down)
ntfy "Ethernet disconnected" "Enabling Wifi"
nmcli radio wifi on
;;
esac
;;
esac
@ks7000
Copy link

ks7000 commented Apr 12, 2019

Reading man nmcli-examples for deeper options...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment