Created
October 3, 2025 16:46
-
-
Save Nachtalb/6951f364982585fb0a785f49e568ed50 to your computer and use it in GitHub Desktop.
Toggle Bluetooth on / off depending on the connected WLAN
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/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