You are not logged in.

#1 2013-01-04 12:01:49

ccc1
Member
Registered: 2009-04-16
Posts: 111

[Solved] Control pulseaudio with shell script via pacmd

Hi,

i wrote a shell script that switches between the internal sound card and an usb card as soon as i dock my laptop. The script is triggered by an acpi-event that's generated when the laptop is docked.
Everything works fine, if the script is run from the command line as the user that started pulseaudio. But if it's started by the acpi-event it can't connect to the pulseaudio server. it's run as:

su --login my_user -c "/usr/local/sbin/toggle-sink.sh"

where my_user is the user who started pulseaudio. i get the error:

 No PulseAudio daemon running, or not running as session daemon.

How can i fix this? Somebody has an idea?

ccc1

Last edited by ccc1 (2013-01-05 11:06:03)

Offline

#2 2013-01-05 05:57:13

Max-P
Member
Registered: 2011-06-11
Posts: 164

Re: [Solved] Control pulseaudio with shell script via pacmd

PulseAudio uses some environment variables and X11 properties on the root window. You probably need a way to fake these.

Have you tried something like

export DISPLAY=":0"

In the script, so it knows on which display these values are stored?

You can also try running "pavucontrol" or "paman"(AUR) from the script, so it pops a window that is supposed to connect to PulseAudio. You might get a working pavucontrol window (which means pacmd and pactl should work), or a more detailled error message.


If this still doesn't work, you may also try running it in system-wide mode, so everybody has access to it including your script.

Offline

#3 2013-01-05 11:05:42

ccc1
Member
Registered: 2009-04-16
Posts: 111

Re: [Solved] Control pulseaudio with shell script via pacmd

Max-P wrote:

PulseAudio uses some environment variables and X11 properties on the root window. You probably need a way to fake these.

That was the right hint. Thanks!

One has to set the variable:

export PULSE_RUNTIME_PATH="/run/your_username/your_uid/pulse/"

and then one can connect with pacmd to the server via:

sudo -u your_username -E pacmd <your_command>

ccc1

Last edited by ccc1 (2013-01-05 14:57:42)

Offline

Board footer

Powered by FluxBB