Turn Airplane Mode on/off via terminal
Running the following command in terminal:
gnome-control-center network
will open a window for network management which should be similar with:
You can observe that at this moment the "Airplane Mode" is off and the wireless is on.
Now, without to close this window, run the following command in terminal:
nmcli nm wifi off
The above window will be changed automatically to:
As you can see, now "Airplane Mode" is on and the wireless is off.
Running, again in terminal, the following command:
nmcli nm wifi off
will turn "Airplane Mode" off and wireless on again.
So, you don't need rfkill
(which need also root privileges) to toggle "Airplane Mode" via terminal.
nmcli
(see also man nmcli
) it's enough and can be executed by any usual user... You don't need root privileges to climb in an airplane :)).
For Ubuntu 18.04:
nmcli r wifi on
turns airplane mode off, and the converse sets it on.
A simple bash script to toggle airplane mode on or off is below; save it to file and set its execute bit in properties.
#!/bin/bash
wifi="$(nmcli r wifi | awk 'FNR = 2 {print $1}')"
if [ "$wifi" == "enabled" ]
then
nmcli r wifi off
else
nmcli r wifi on
fi
Tested on 20.04.1 LTS. Let's disable all radio transmissions:
rudy@nbu130-rudy:~/bin$ pwd
/home/rudy/bin
rudy@nbu130-rudy:~/bin$ ./airplane_toggle
rudy@nbu130-rudy:~/bin$ nmcli radio all
WIFI-HW WIFI WWAN-HW WWAN
enabled enabled enabled enabled
rudy@nbu130-rudy:~/bin$ ./airplane_toggle
rudy@nbu130-rudy:~/bin$ nmcli radio all
WIFI-HW WIFI WWAN-HW WWAN
enabled disabled enabled disabled
rudy@nbu130-rudy:~/bin$ cat airplane_toggle
#!/bin/bash
radio="$(nmcli radio all | awk 'FNR == 2 {print $2}')"
if [ "$radio" == "enabled" ]
then
nmcli radio all off
else
nmcli radio all on
fi
It is even possible to assign the command '/home/rudy/bin/airplane_toggle' to a shortcut (tested).