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

4
  • I don't think that silent mode settings are managed using dconf. If you connect to your phone from your computer (enable developer mode on phone, run adb shell from terminal on computer), watch for dconf changes: dconf watch / and then toggle silent mode in the phone settings, then no changes to dconf are recorded. (However, if you, say toggle "Keyboard sound", then you do see /com/canonical/keyboard/maliit/key-press-feedback false so it's not just the case that dconf watch isn't working.)
    – aplaice
    Jul 19, 2016 at 19:13
  • I think that running dbus-monitor "path=/com/canonical/indicator/sound" (in a terminal "debugging" your phone), toggling the "silent mode" setting and then somehow duplicating the signal sent (using dbus-send) might be promising, but I do not really understand dbus.
    – aplaice
    Jul 19, 2016 at 20:12
  • Indeed. Its odd. I even went as far as searching all the files on my phone for the word silent but nothing relevant could be found. EDIT: I'll be looking into the dbus thing, thanks.
    – Wieke
    Jul 19, 2016 at 20:12
  • 1
    I figured it out using python and the qdbus cli tool. I was using qdbus up to the point where I figured out how to call the relevant method but I couldn't figure out how to format the argument so it's interpreted as a boolean instead of a string. Using python was a workaround.
    – Wieke
    Jul 19, 2016 at 23:12

2 Answers 2

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

1
  • Wouldn't this just turn off the sound? That's not exactly the same as turning on silent mode (it wouldn't stop vibration).
    – Wieke
    Jul 19, 2016 at 22:12
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .