0

I am following this question to set my volume levels from the command line. I need to be able to set the volume from within a tmux session (actually from a node process running in tmux).

When I run amixer -D pulse sset Master 50% straight in my ssh session, it works just fine.

$ amixer -D pulse sset Master 50%
Simple mixer control 'Master',0
  Capabilities: pvolume pswitch pswitch-joined
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 65536
  Mono:
  Front Left: Playback 26214 [50%] [on]
  Front Right: Playback 26214 [50%] [on]

If I open tmux, then run the same command, it fails:

$ tmux
...
$ amixer -D pulse sset Master 50%
ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

amixer: Mixer attach pulse error: Connection refused

Within node, I'm just using the child_process.spawn function which gives the same result as running from tmux, so I assume they are related.

What gives?

Nolan B.
  • 101

1 Answers1

0

For this curious, this was because my tmux session was started from a system-wide service file, and didn't have the environment variables set up to talk to the user-level pulseaudio service.

Fixed by just prepending the following string to my amixer command:

PULSE_SERVER=unix:/run/user/1000/pulse/native

like so:

$ PULSE_SERVER=unix:/run/user/1000/pulse/native amixer -D pulse sset Master 50%

The /run/user/1000 may be different, you can determine it running

$ echo $XDG_RUNTIME_DIR

In a session logged in as user with the pulseaudio session you'd like to use.

Nolan B.
  • 101