Is it possible to setup a shortcut for enable/disable wifi?

This script will toggle the status, and show a message to confirm what's been done.

#!/bin/bash

if [ $(rfkill list wifi | grep "Soft blocked: yes" | wc -l) -gt 0 ] ; then
    rfkill unblock wifi
    zenity --info --text "Enabled wireless"
else
    rfkill block wifi
    zenity --info --text "Disabled wireless"
fi

To have the zenity prompts disappear, change them like so:

zenity --info --text "Enabled wireless" --timeout="5"
zenity --info --text "Disabled wireless" --timeout="5"

Or make notifications that appear in the corner of your screen. alt text

sudo apt-get install libnotify-bin

Replace the zenity lines with

notify-send -i network-wireless-full "Wireless enabled" "Your wireless adaptor has been enabled."
notify-send -i network-wireless-disconnected "Wireless disabled" "Your wireless adaptor has been disabled."

I've been looking for a solution to this for myself for a while, and have used a lot of tips and tricks for all over. I've finally found the solution that works for me, and decided to create a newbie walk-through. Bear with me, this is also for those less able to program in linux than many of you, like myself;

Click the launcher icon on the top left slide out bar (Dash Home), type in 'gedit', and click enter.

You're now going to create the script that will toggle the wifi;

I used the network manager shortcut; nmcli nm wifi, to determine the wifi state, and also to control it. I used the notification script given in the above example to display the wifi state. Here's my script;

#!/bin/bash

if [ $(nmcli nm wifi | grep "disabled" | wc -l) -eq 1 ] ; then
    nmcli nm wifi on
    notify-send -i network-wireless-full "Wireless enabled" "Your   wireless adaptor has been enabled."
else
    nmcli nm wifi off
    notify-send -i network-wireless-disconnected "Wireless disabled"    "Your wireless adaptor has been disabled."
fi

Copy and paste this into the editor that you just opened, and save it as any filename you find appropriate (mine was wifitoggle).

Next step was to make the file executable (in Home Folder; right click your file, properties, permissions tab, check mark on 'Run as executable').

Then place a copy in the file system /usr/bin directory (open terminal, type sudo nautilus. Navigate to File system, then usr, then open bin. Paste y).

Finally, go to System Settings -> Keyboard -> Shortcuts tab; press the little + button underneath, fill in the name for your toggle and fill in the filename for the script you gave (in my case wifitoggle). Click apply, and click on the 'diabled' text to the right of that, and then press your hot keys. DONE!


To disable your wifi adapter use rfkill block wifi, to enable it use rfkill unblock wifi

Instead of wifi you can use one of the following keywords: all wifi wlan bluetooth uwb ultrawideband wimax wwan gps fm