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