On my Ubuntu desktop the volume at 100% is often too quiet. With Ubuntu’s default window manager I could open up the graphical “Sound Preferences” and bump the volume to above 100%. After using i3 window manager for a while I found myself missing this and took the time to figure out how to do it from the command line.
Ubuntu uses PulseAudio to handle sound related tasks. The tool pacmd allows you to change PulseAudio settings, such as volume, on the fly. The command is
pacmd set-sink-volume <sink-index> <sink-volume> where
<sink-index> is an identifier for your output device and
<sink-volume> is an integer greater than or equal to zero. Zero represents muted and 65536 represents 100% volume.
<sink-index> is the index found in the output from the
pacmd list-sinks for your output card. In my case it is 0.
The below script makes changing volume with
pacmd straightforward. I’m using Perl convert a percentage into the proper units for the
1 2 3 4 5 6 7 8 9 10