Skip to content

Instantly share code, notes, and snippets.

@Nachtalb
Created October 3, 2025 16:46
Show Gist options
  • Select an option

  • Save Nachtalb/6951f364982585fb0a785f49e568ed50 to your computer and use it in GitHub Desktop.

Select an option

Save Nachtalb/6951f364982585fb0a785f49e568ed50 to your computer and use it in GitHub Desktop.
Toggle Bluetooth on / off depending on the connected WLAN
#!/bin/bash
# /etc/NetworkManager/dispatcher.d/99-toggle-bluetooth
set -euo pipefail
IFACE="$1"
ACTION="$2"
[[ "$ACTION" == "up" ]] || exit 0
iw dev "$IFACE" info >/dev/null 2>&1 || exit 0
SSID="$(iw dev "${IFACE}" link | awk -F': ' '/SSID/ {print $2}')"
# echo "SSID: $SSID"
# echo "IFACE: $IFACE"
# echo "ACTION: $ACTION"
case "$SSID" in
"Hidden Network")
if [[ -z "$(bluetoothctl devices Connected)" ]]; then
bluetoothctl power off
notify-send "Bluetooth turned off" -t 5000 --icon /usr/share/icons/BeautyLine/apps/scalable/bluetooth.svg
fi
;;
"FDF-Strand")
bluetoothctl power on
notify-send "Bluetooth turned on" -t 5000 --icon /usr/share/icons/BeautyLine/apps/scalable/bluetooth.svg
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment