volume control from guix cli with pactl instead of amixer

Table of Contents

Intro

I used to have an exwm emacs shortcut to change my volume:

(exwm-input-set-key (kbd "<XF86AudioLowerVolume>") (lambda () (interactive) (shell-command "amixer set Master 2%-")))

and a similar function for the volume-up key. When I press the audio buttons, it uses amixer to change the volume.

The trouble is, guix doesn’t seem to offer amixer anywhere. I don’t see it in nongnu packages, so I was able to find pactl instead. Here’s how I got it (improvement suggestions welcome):

Answer with pactl

guix install bluez-alsa # got the bundle, which was okay since I want bluetooth later
guix install pavucontrol

Then I had pactl, and the following did what the equivalent of what I had before:

(defun tsa/change-volume (amount-str) (interactive)
       (shell-command (concat "pactl set-sink-volume 0 " amount-str))
       (shell-command-to-string "pactl get-sink-volume 0"))

The shell-command-to-string is needed to get the actual output of the program, since the return value of the program was always 0 (old-style “success”).

Then, in my exwm configuration, the following to bind it (restart needed to get exwm to load it)

(exwm-input-set-key (kbd "<XF86AudioLowerVolume>") (lambda () (interactive) (tsa/change-volume "-2%")))
(exwm-input-set-key (kbd "<XF86AudioRaiseVolume>") (lambda () (interactive) (tsa/change-volume "+2%")))
Tory Anderson avatar
Tory Anderson
Full-time Web App Engineer, Digital Humanist, Researcher, Computer Psychologist