Bash script for enabling/disabling wireless connection on linux based systems using rfkill. Ideal for binding to a keyboard shortcut.
rfkill
and libnotify-bin
copy paste friendly command for Debian based distros:
sudo apt install rfkill libnotify-bin
copy paste friendly command for Arch based distros:
sudo pacman -S rfkill libnotify-bin
sudo chmod +x wifi-switch.sh
Bind it to keyboard shortcut using xbindkeys:
- In debian based distributions run:
sudo apt install xbindkeys
- In arch based distributions run:
sudo pacman -S xbindkeys
xbindkeys -d > ~/.xbindkeysrc
- Start
xbindkeys
:
xbindkeys
- Open config file with your favourite editor:
vi ~/.xbindkeysrc
- Add this to .xbindkeys if
wifi-switch.sh
is in yourhome
directory:
"./wifi-switch.sh"
alt+y
or any other key combination. If wifi-switch.sh
is not in your home directory point it to it with an absolute path to script.
- Reload the config file:
killall -s1 xbindkeys
or
xbindkeys --poll-rc
https://wiki.archlinux.org/index.php/Xbindkeys
Go to Settings
and navigate to Keyboard/Keyboard Shortcuts
. Scroll down until you see +
and click on it. A small window with title Add Custom Shortcut
will open with 3 fileds to set. Set Name
to whatever you want. Under command enter a absolute/path/to/script
(if wifi-switch.sh
is in your home
directory it should look like this /home/YourUsername/wifi-switch.sh
). Next click on set shortcut and enter your key combination.