5

I'm looking for a way to automatically set my Ubuntu Phone to silent mode during the night and automatically turn off silent mode in the morning (I keep forgetting to turn it off myself). I figure this could be done through some kind of cron job but in order to do that I need some way of changing the phones system settings from the command line and I can't figure it out.

Both gsettings and dconf seem to have silent-mode related settings but the value of these settings doesn't seem to be related at all to the real settings. Changing the settings using gsettings/dconf isn't reflected in the system settings and changing it in system settings isn't reflected in gsettings/dconf. So I'm looking for a way to change system settings from command line.

Thanks

Wieke
  • 161

2 Answers2

1

It seems to work (with OTA-11, connect with SSH):

amixer -q -D pulse sset Master toggle

Edit: From https://askubuntu.com/a/444183

Silvus
  • 11
1

Solution(ish)

Apparently dbus is a thing that could be used to change settings. The short version is that the following python script, when ran as root, turns off silent mode:

import dbus

session = dbus.SystemBus()
proxy = session.get_object('org.freedesktop.Accounts','/org/freedesktop/Accounts/User#####')
interface = dbus.Interface(proxy,'org.freedesktop.DBus.Properties')
interface.Set('com.ubuntu.touch.AccountsService.Sound','SilentMode',False)

The slightly longer version is:

qdbus --system

Seems to list all the services associated with the system dbus.

qdbus --system org.freedesktop.Accounts

Seems to list the paths associated with that service.

qdbus --system org.freedesktop.Accounts /org/freedesktop/Accounts/User#####

Seems to list all the methods and properties associated with that path (in this case a path to a specific user). This had the following relevant methods:

method QDBusVariant org.freedesktop.DBus.Properties.Get(QString interface_name, QString property_name)    
method QVariantMap org.freedesktop.DBus.Properties.GetAll(QString interface_name)
method void org.freedesktop.DBus.Properties.Set(QString interface_name, QString property_name, QDBusVariant value)
method QString org.freedesktop.DBus.Introspectable.Introspect()

Here the GetAll and Set methods require an interface name which we can find out by calling the Introspect function like this:

qdbus --system org.freedesktop.Accounts /org/freedesktop/Accounts/User##### org.freedesktop.DBus.Introspectable.Introspect

Which prints a xml-like document to the screen showing the interface definitions. Getting the silent mode value is done as follows:

qdbus --system org.freedesktop.Accounts /org/freedesktop/Accounts/User##### org.freedesktop.DBus.Properties.Get com.ubuntu.touch.AccountsService.Sound SilentMode

The problem now was that I couldn't figure out how to format it so qdbus interprets an argument as a boolean value, which is why I ended up using python as a workaround.

Wieke
  • 161