I have the following script (in my PATH):
#!/usr/bin/env bash
main()
{
local state=$(sudo rfkill list wifi -n -o SOFT)
if [[ $state == 'blocked' ]]
then
sudo rfkill unblock wifi
state='Unblocked'
else
sudo rfkill block wifi
state='Blocked'
fi
notify-send 'Wi-Fi' "$state"
exit 0
}
main $@
Running the script from the command line works as expected, then I add the following shortcut to my.xbindkeysrc
:
"kill-wifi"
XF86WLAN
But the notifications, and the Wi-Fi interface get stuck in one of the two states, blocked
or unblocked
, it doesn't toggle. Sometimes, if I press several times the XF86WLAN
key, I get a toggle.
The weird thing is that using another key to trigger the script, such as F8, the whole thing works fine, but I want to leave F8 for purposes other than toggling the WiFi.
So one of my guesses was that there's "something" binding the XF86LAN KeySym that messes up when my script runs. But then commenting out the command that actually kills the WiFi interface, produces the right notifications (but I'm not actually doing anything useful).
Any pointers would be appreciated.