I run Ubuntu 18.04 on my HP, and before dual booting, when I only had Windows, I would always press the F12 key to turn the Wifi on and off easily. Now that is the only key that doesn't work on Ubuntu.
I've already tried bash scripts and keyboard settings, to no avail. At most, I managed to get messages to show up, but the wifi stayed the same. (also, the settings won't let me set F12 alone, so I set Ctrl+F12; though right now that's the least of my concerns)
Until now, I have this:
#!/bin/sh
if [ $(nmcli nm wifi | awk '/led/ {print}') = 'enabled' ] ; then
nmcli nm wifi off
# notify-send -i network-wireless-none "Wireless" "Wireless disabled"
echo 'wifi off'
else
nmcli nm wifi on
notify-send -i network-wireless-none "Wireless" "Wireless enabled"
echo 'wifi on'
fi
What could be wrong?
Just make a file, say, called 'toggle_wifi.sh' (contents listed below), make it executable and stick it into /usr/local/bin/ directory, then add a Keyboards Shortcut in Settings.
toggle_wifi.sh file contents:-
Thanks to those above who have given me the core instructions, been meaning to figure out how to do this for a while.
F12 should be bindable. Have you tried going to Settings > Devices > Keyboard and adding a custom bind from the bottom of the page?
Either way, the script should work if you change these two lines:
To: