In this post I show two ways to display the audio volume as a percentage in the Panel and Conky using amixer and pamixer. The primary differences are:
- amixer:
Uses an existing MX Linux package.
To get the volume percentage output in the Panel or Conky a file must be created and then a path to the file is used to run the command. The command consists of amixer and grep and thus will not work if that command is put in the "Generic Monitor" or Conky.
When the volume is muted, "muted" is NOT displayed (the existing volume percentage will remain).
- pamixer:
Not an existing application so it must be installed (Stable Repository).
To get the volume percentage output in the Panel or Conky only the (absolute) path to pamixer is used. No need to create a file to run the command.
When the volume is muted, "muted" is displayed in place of the percentage.
Using amixer to display the volume percentage in the Panel
1. Create a file for the amixer command. I am using /home/<username>/.volumepercent in this example so adjust as desired.
2. Make that file executable such as:
- right-click the file > Properties > Permissions tab > enable "Allow this file to run as a program"
-or- - In a Terminal run chmod -c u+x .volumepercent
Code: Select all
#!/bin/sh
amixer -c<n> -M | grep -oP -m 1 '\[\K[^]]*%'
If the percentage symbol (%) is not wanted to be displayed then use the below instead:
Code: Select all
#!/bin/sh
amixer -c<n> -M | grep -oP -m 1 '\[\K[^]]*%' | tr -d '%'
Edit-2 end
Here are four ways to get the soundcard number to use:
Code: Select all
aplay -l
Code: Select all
cat /proc/asound/cards
- alsamixer > F6 (Select sound card) > view available soundcards
- Shotgun it by trying all possible soundcard numbers until the correct percentage is displayed (there should only be a couple/few options).
4. Add "Generic Monitor" to the Panel and fill out the fields as follows:
- Command: Use the absolute path to the created file which in this example is /home/<username>/.volumepercent
- Label: As desired (it is disabled in the below images)
- Period (s): As desired (refresh period in seconds)
- Font: As desired (FreeSans 12 is used in the below images)
5. Go to /home/<username>/.config/gtk-3.0/gtk.css and enter the following text in the gtk.css file ("#00cccc" is used in the images here - change as desired). Remember to replace <n> for the plugin ID (see below):
Code: Select all
#genmon-<n> {color: #00cccc}
- Panel Properties > Items tab > hover the mouse pointer over the plugin and look for the number after the hyphen.
- Look for "genmon" in /home/<username>/.config/xfce4/panel/
Code: Select all
xfconf-query -c xfce4-panel -lv | grep genmon | awk '{print $1}' | awk -F'-' '{print $2}'
Code: Select all
xfce4-panel -r
Using amixer to display the volume percentage in Conky
7. Use steps 1-3 above to create a file to run the command.
8. Insert the line in the below code window into Conky. The number after "execi" is the interval in seconds that the code will run. Edit as desired, as well as the text that will be displayed ("Volume: "):
Code: Select all
Volume: ${execi 2 /home/<username>/.volumepercent }
- Change the font and font size to what follows the code (Verdana size 12 is used as an example):
Code: Select all
${font Verdana:size=12}
- Aligns the output of the code that follows it to the right margin:
Code: Select all
${alignr}
Using pamixer to display the volume percentage in the Panel
9. Install pamixer from the Stable Respository.
10. Use step 4 above EXCEPT the command field is changed as follows:
Code: Select all
/usr/bin/pamixer --get-volume-human
The below image shows MX-21 with pamixer (with the Label field disabled). Note that when the audio is muted, "mute" is displayed as shown in the lower Panel image. Also pamixer is often off by 1% throughout the output range in comparison to the VolumeIcon volume level. (The Linear Scale is enabled in VolumeIcon > Preferences > Channels tab.)
Pamixer will not display 0% when the output volume is set to 0% using either the linear or logarithmic scales. This is why you see 11% displayed in the below image when the audio level is set to 10% (amixer displays the output level identical to the VolumeIcon volume level throughout the range). A minor point but a point nevertheless.
Using pamixer to display the volume percentage in Conky
12. The code to add in Conky is:
Code: Select all
Volume: ${execi 2 /usr/bin/pamixer --get-volume-human }
Edit-2 (7 February 2023): As noted between red two Edit-2 lines above.