[systemd] [command line] How to automatically enable/disable flight mode

Can’t believe it has not been said somewhere.
But I didn’t find on TJC nor here, neither in the cheat sheet.

I have a secondary phone with a few used SIM card.
I just want to make a timer to put it online shortly sometimes, to avoid loosing eventual SMSes.
I will make a systemd timer for that.

But how can I switch flight mode on and off from a command line?
Thank you

1 Like

I think mcetool can do that.

-r, --enable-radio=<master|cellular|wlan|bluetooth>
enable the specified radio; valid radios are:
‘master’, ‘cellular’,
‘wlan’ and ‘bluetooth’;
‘master’ affects all radios

-R, --disable-radio=<master|cellular|wlan|bluetooth>
disable the specified radio; valid radios are:
‘master’, ‘cellular’,
‘wlan’ and ‘bluetooth’;
‘master’ affects all radios

1 Like

It’s on TJC here :slight_smile:

1 Like

Great, thanks, thanks, thanks !
This page is a holy page!
(hmm, some search skills to improve tho I spent time…)

For the record, here is how I did, thanks to other users help.
Perhaps it can serve someone else.
But it’s one more noob2noob tuto: There are much more skilled people here. They could explain this better, in a more correct way to do things and in a more richer way. But they have more important things to do (develop apps, catch bugs, try to push/pull Jolla…), so I do it with my modest knowledge.

To switch on airplane mode:

dbus-send --system --dest=com.nokia.mce --print-reply /com/nokia/mce/request com.nokia.mce.request.req_radio_states_change uint32:0 uint32:1

To switch off airplane mode:

dbus-send --system --dest=com.nokia.mce --print-reply /com/nokia/mce/request com.nokia.mce.request.req_radio_states_change uint32:1 uint32:1

And to run this task repetitively and automatically, one can use systemd timers.
Here is how I did. It is working. But correct me if there’s a better way.


The goal: Having the phone connected to cellular network 15 minutes per day only.

1.The scripts
I needed two scripts. One to disable airplane mode, the other one to re-enable airplane mode.

/home/somewhere/airplane_off.sh:

#!/bin/bash
dbus-send --system --dest=com.nokia.mce --print-reply /com/nokia/mce/request com.nokia.mce.request.req_radio_states_change uint32:1 uint32:1

/home/somewhere/airplane_on.sh:

#!/bin/bash
dbus-send --system --dest=com.nokia.mce --print-reply /com/nokia/mce/request com.nokia.mce.request.req_radio_states_change uint32:0 uint32:1

Make the scripts executable:

chmod +x /home/somewhere/airplane_*.sh

2.Service files
These files describe what is to be done. Actually, execute the above .sh scripts.

/etc/systemd/system/ric9k_airplane_off.service:

[Unit]
Description=Run a script to turn airplane mode off

[Service]
ExecStart=/home/somewhere/airplane_off.sh

/etc/systemd/system/ric9k_airplane_on.service:

[Unit]
Description=Run a script to turn airplane mode on

[Service]
ExecStart=/home/somewhere/airplane_on.sh

3.The timer files
Mainly, they tell the system when to run the above service.

/etc/systemd/system/ric9k_airplane_off.timer:

[Unit]
Description=Auto system backup

[Timer]
WakeSystem=true
OnCalendar=--* 12:00:00
AccuracySec=1800
Persistent=true

[Install]
WantedBy=timers.target

/etc/systemd/system/ric9k_airplane_on.timer:

[Unit]
Description=Auto system backup

[Timer]
WakeSystem=true
OnCalendar=--* 12:15:00
AccuracySec=1800
Persistent=true

[Install]
WantedBy=timers.target

Then, to enable the timers, still as root, run:

systemctl enable ric9k_airplane_off.timer
systemctl enable ric9k_airplane_on.timer

(use disable to unactivate)

This description is a short introduction, not even the tip of the iceberg. But systemd offers a lot of functional options and timing solutions. (I read and forgot all of them so please search the web for more info)

As my phone and it’s clone -the spare phone- are both used with two users (one user with no data for Android apps and one user for private life), I used systemd timer as service instead of as user.

Also, a previous experience was not working as user for a question of rights so I was too lazy to try again as user. But I think this would be recomanded… well, approximative tinkering…

3 Likes