We have moved to a new Sailfish OS Forum. Please start new discussions there.
3

Is there a way to control media volume from command line? [answered]

asked 2019-02-20 17:58:45 +0300

naytsyrhc gravatar image

First of all: I have read following quite similar questions and corresponding answers you will find related to this:

Audio control in sailfish: Setting volume via cmd-line

But my question is different. I don't want to change maximum output volume to be louder than 100% nor do I want to change the base value of a sink in pulse audio.

I really want to control the volume that I can normally control with the hardware keys.

Is there a way to do this by a command executed from command line?

From @dthierbach answer here I know how to read the current value, but I couldn't figure out how to write it.

Motivation: I'd like to set output volume to specific value on specific situations. Situations app has the feature to set ringtone volume based on situations but not media volume. But situations app can issue commands. So if I could control volume from command line, I could create such an action by myself.

edit retag flag offensive reopen delete

The question has been closed for the following reason "the question is answered, an answer was accepted" by naytsyrhc
close date 2019-02-24 10:57:47.418380

Comments

try looking at pactl

coderus ( 2019-02-20 18:57:46 +0300 )edit

@coderus I had a look at pactl already. But as far as I can see pactl unfortunately only sets the volume levels for the sinks. So this is a nice approach for setting maximum allowed volume to a specific value, but it is not sufficient for my use case. Description: I get into the car and the situation is recognized by bluetooth connection, I want to set output volume to maximum. If I use pactl and set volume to 100%, volume will not be 100%, as I might have changed the media volume by hardware keys to e.g. 60%. So the overall volume ist 60% (media) of 100% (sink). If I want to set volume to say 50% if I connect my headphone and I set sink volume to 50% but my media volume was 20% I only get 50% of 20% (e.g. 10%). So I'd like to leave sink volumes untouched but directly control overall media volume.

naytsyrhc ( 2019-02-20 19:06:33 +0300 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2019-02-21 01:00:19 +0300

naytsyrhc gravatar image

updated 2019-02-21 01:00:55 +0300

Ok. I'm a bit closer to what I want. I found out that getting a specific value (current volume) can be done by

dbus-send --print-reply --type=method_call --address='unix:path=/run/user/100000/pulse/dbus-socket' --dest=org.Meego.MainVolume2 /com/meego/mainvolume2 org.freedesktop.DBus.Properties.Get string:com.Meego.MainVolume2  string:CurrentStep

In order to change the value, I can do this:

dbus-send --print-reply --type=method_call --address='unix:path=/run/user/100000/pulse/dbus-socket' --dest=org.Meego.MainVolume2 /com/meego/mainvolume2 org.freedesktop.DBus.Properties.Set string:com.Meego.MainVolume2  string:CurrentStep variant:uint32:5

Only problem I still have is, that mainvolume2 seems to change behaviour. Sometimes it's media volume, sometimes it's ringtone volume. Is there a way to fixate that to always control media volume?

edit flag offensive delete publish link more

Comments

I used alsamixer plain old tool and it works, but I am not sure if it fits your question as it is command line gui

deloptes ( 2019-02-24 02:18:11 +0300 )edit

Command line is ok. But I already achieved what I wanted by above dbus commands. Only issue is that this only effects media volume if some media app is running. For now I can live with that. Thanks anyway.

naytsyrhc ( 2019-02-24 10:57:15 +0300 )edit

Just for the record alsamixer controls the output volume of PA not the sinks

deloptes ( 2019-02-24 11:09:18 +0300 )edit
1

Hi, not sure if you're still interested but I recently had the same problem and managed to control the media volume directly via the python script from here: https://wiki.merproject.org/wiki/Nemo/Audio, https://raw.github.com/jusa/pulseaudio-utils/master/pasr.py. I'm able to do python2 pasr.py set sink-input-by-media-role:x-maemo 30000 to set the media volume. This is done automatically through the situations app which calls a script. (In my case when the car bluetooth is connected)

rod ( 2019-09-11 19:36:31 +0300 )edit

Thanks. Will have a look into this. Actually my use case is exactly the same (set media volume to max on car bluetooth connection and set media volume to half for bluetooth headphones).

naytsyrhc ( 2019-09-17 10:51:29 +0300 )edit

Question tools

Follow
2 followers

Stats

Asked: 2019-02-20 17:58:45 +0300

Seen: 351 times

Last updated: Feb 21 '19