You are not logged in.

#1 2011-08-14 19:30:46

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,343
Website

pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

Use this little script  to control your pulseaudio volume from within xfce4 or other DE's via mapped keys on the keyboard (mine actually has keys for mute, vol+ and vol-).  Mapping shortcut keys varies from DE to DE.  On xfce4, the you can do this under Settings > Keyboard > Application Shortcuts.

Usage is very simple:
/usr/bin/pulseaudio-ctl mute will toggle status of mute
/usr/bin/pulseaudio-ctl up will increase vol by 5 %
/usr/bin/pulseaudio-ctl down will decrease vol by 5 %

You can map these three actions to three keyboard shortcuts for quick access.  My keyboard actually has discrete buttons for these actions:
keyboard.jpg

If you execute the script from the shell, it will output the above and also show the current vol level and mute status:

% pulseaudio-ctl
pulseaudio-ctl v1.45

/usr/bin/pulseaudio-ctl {up,down,mute,mute-input,set,atmost} [n]
Where up and down adjust volume in ±5 % increments.
Where mute toggles the mute status on/off.
Where mute-input toggles the input status on/off.
Where set takes a % value.
Where atmost only takes effect if current volume is higher than this.

Optionally, redefine an upper threshold in /home/facade/.config/pulseaudio-ctl/config

Volume level     : 90 %
Is sink muted    : no
Is source muted  : no
Detected sink    : 1
Detected source  : 1
Pulse version    : 5.0

UPDATE on 03-Nov-2014: Now uses libnotify to show vol level and mute status.

AUR: https://aur.archlinux.org/packages/pulseaudio-ctl
GitHub: https://github.com/graysky2/pulseaudio-ctl

Last edited by graysky (2014-11-03 08:38:27)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2011-08-14 20:47:03

twix
Member
Registered: 2010-10-07
Posts: 63

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

Cool, i was looking for something like that, but I didn't know pacmd (btw not enough search).

Maybe you should modify the link in AUR to point to this forum.

Thank you for this scripts !

Last edited by twix (2011-08-14 20:47:11)

Offline

#3 2011-08-14 21:04:36

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,343
Website

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

Done.  Enjoy!


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#4 2012-04-05 01:08:31

sankeytm
Member
From: California
Registered: 2012-03-05
Posts: 28

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

If it matters, I have reduced the number of calls to pacmd:

diff -Nru /usr/bin/vol_up vol_up 
--- /usr/bin/vol_up	2012-03-05 03:22:47.000000000 -0800
+++ vol_up	2012-04-04 18:03:39.470194066 -0700
@@ -8,12 +8,7 @@
 sink=`pacmd info|grep "Default sink name"|awk '{print $4}'`
 
 # Now we need to find volume of default sink
-# get line# of start of definition for default sink (plus 1, actually)
-let line=`pacmd list-sinks|grep -n $sink|sed '{s/://}'|awk '{print $1}'`
-
-# index down a bit for volume line
-let line=($line + 6)
-volume=`pacmd list-sinks|awk 'NR=="'"$line"'"{print $3}'|sed '{s/%//}'`
+volume=`pacmd list-sinks|grep -A 6 $sink|awk 'NR==7{print $3}'|sed '{s/%//}'`
 
 # pacmd returns volume as %, but demands setting as range: 0-65535
 let volume=($volume * 65536);let volume=($volume / 100)

I have taken this code and modified it for use in my dwm status bar (to determine current volume level). Since it gets called every 5 seconds, this optimization is important to me smile

edit: I'm not sure where bug reports for aur packages go. Perhaps it's better to comment on the aur page?

Last edited by sankeytm (2012-04-05 02:51:47)

Offline

#5 2012-04-05 04:16:30

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 6,772

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

Didn't see this when first posted, but my own command-line control of pulseaudio's volume simply involves amixer -D pulse, so for increasing the volume I just use:-

amixer -D pulse sset Master 5%+

Much simpler IMO, and no need to worry about overflow etc.


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#6 2012-04-05 07:32:45

sankeytm
Member
From: California
Registered: 2012-03-05
Posts: 28

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

Okay, now amixer replaces all three files in this package.
vol_up: amixer -D pulse sset Master 5%+
vol_down: amixer -D pulse sset Master 5%-
mute_toggle: amixer -D pulse sset Master toggle

It seems to work identically. It even knows to apply changes to the (current) default sink. Is there any more use for this package (pulseaudio_ctl)?

For my status bar I still need to determine the current volume of the default sink. Right now I'm extracting bits of amixer's output:
amixer -D pulse sget Master | awk '/Front Left:/ {print $4}'
or just the percentage:
amixer -D pulse sget Master | awk '/Front Left:/ {print $5}' | tr -dc "0-9"

Does anybody know of a simpler, possibly single-command way of doing it? Is It worth patching amixer, or is using awk to extract numbers the intended use?

edit: found aur/pamixer-git which has --get-volume which returns the volume in percentage.

Last edited by sankeytm (2012-04-05 08:10:03)

Offline

#7 2012-05-10 14:00:51

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,343
Website

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

ngoonee wrote:

Didn't see this when first posted, but my own command-line control of pulseaudio's volume simply involves amixer -D pulse, so for increasing the volume I just use:-

amixer -D pulse sset Master 5%+

Much simpler IMO, and no need to worry about overflow etc.

Late reply but amixer is an additional dependency... no need for extra/alsa-utils with these scripts smile


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#8 2012-05-11 02:14:29

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 6,772

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

graysky wrote:
ngoonee wrote:

Didn't see this when first posted, but my own command-line control of pulseaudio's volume simply involves amixer -D pulse, so for increasing the volume I just use:-

amixer -D pulse sset Master 5%+

Much simpler IMO, and no need to worry about overflow etc.

Late reply but amixer is an additional dependency... no need for extra/alsa-utils with these scripts smile

Yep, I'm sure most people using alsa don't use alsa-utils for other stuff (like, for example, saving the volume on reboot?) smile


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#9 2012-05-11 02:18:47

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,343
Website

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

ngoonee wrote:

Yep, I'm sure most people using alsa don't use alsa-utils for other stuff (like, for example, saving the volume on reboot?) smile

I don't understand... my system has been fine for months without the alsa-utils package running only pulse-audio... are you mocking me hmm


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#10 2012-05-11 02:22:02

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 6,772

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

graysky wrote:
ngoonee wrote:

Yep, I'm sure most people using alsa don't use alsa-utils for other stuff (like, for example, saving the volume on reboot?) smile

I don't understand... my system has been fine for months without the alsa-utils package running only pulse-audio... are you mocking me hmm

Probably because your default volumes are fine. As I understand it, the alsa rc.d script is needed because some systems require adjustment to the amixer values to be 'saved'. Mine doesn't, but I don't mind the 2 MB package very much.


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#11 2012-09-06 13:30:46

robotanarchy
Member
Registered: 2012-09-03
Posts: 17

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

Thanks for the scripts, I was looking for that on my xfce install smile

EDIT: I'll use the amixer one. But without this thread I wouldn't have found it here smile

EDIT2: Wait, I didn't have amixer installed either.

Your script:
Total Installed Size:   0.01 MiB

dialog, alsa-utils:
Total Installed Size:  3,27 MiB

Then I'll use your fine script!

Last edited by robotanarchy (2012-09-06 13:35:29)

Offline

#12 2012-09-08 12:20:11

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,343
Website

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

robotanarchy wrote:

EDIT2: Wait, I didn't have amixer installed either.

Your script:
Total Installed Size:   0.01 MiB

dialog, alsa-utils:
Total Installed Size:  3,27 MiB

Then I'll use your fine script!

That's my logic as well smile


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#13 2013-10-11 23:52:20

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,343
Website

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

Updated to reflect a much more simplistic, single control script.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#14 2014-04-06 18:41:43

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

@graysky

Thanks for this promising script! I am wondering why it does not recognise my running pulseaudio session?

~ /usr/bin/pulseaudio-ctl mute
No PulseAudio daemon running, or not running as session daemon.
No PulseAudio daemon running, or not running as session daemon.
No PulseAudio daemon running, or not running as session daemon.
No PulseAudio daemon running, or not running as session daemon.
No PulseAudio daemon running, or not running as session daemon.
No PulseAudio daemon running, or not running as session daemon.
 Cannot find current volume. CURVOL = 
~ ps aux | grep pulse
orschiro 27720  0.0  0.0 352948  6264 ?        SNl  20:23   0:00 pulseaudio --start
orschiro 27746  0.0  0.0  76484  2716 ?        SN   20:24   0:00 /usr/lib/pulse/gconf-helper

Offline

#15 2014-05-04 15:04:22

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,343
Website

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

This I do not know... try 1.37-1 and report back.

Last edited by graysky (2014-05-04 15:09:34)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#16 2014-05-05 11:32:31

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

Something different broke now with the recent update:

~ /usr/bin/pulseaudio-ctl mute 
/usr/share/pulseaudio-ctl/config.skel is missing. Reinstall this package to continue.

Reinstalling the package does not help.

Last edited by orschiro (2014-05-05 11:46:06)

Offline

#17 2014-05-05 17:22:31

petecan
Member
Registered: 2013-05-02
Posts: 2

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

Temporary solution:

sudo ln -s /usr/share/pulseaudio-ctl/pulseaudio-ctl.conf.skel /usr/share/pulseaudio-ctl/config.skel

Offline

#18 2014-05-05 18:28:32

kalsan
Member
Registered: 2011-10-10
Posts: 84

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

Thank you petecan for this workaround. Please excuse if my question is too stupid: At the next update, will it be necessary to do any further steps (e.g. remove the created link)?

Offline

#19 2014-05-05 20:03:43

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,343
Website

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

Ack, my bad.. .typo in the Makefile.  Fixed now in 1.39-1.  Please try it.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#20 2014-05-06 05:46:26

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

@graysky

Your update seems to have fixed my issue from above. Thanks!

Offline

#21 2014-08-17 02:13:04

jdevelop
Member
Registered: 2014-04-18
Posts: 18

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

with xbindkeys it's that simple as

"/sbin/amixer -D pulse sset Master 10%-"
    m:0x10 + c:122
    Mod2 + XF86AudioLowerVolume
"/sbin/amixer -D pulse sset Master 10%+"
    m:0x10 + c:123
    Mod2 + XF86AudioRaiseVolume
"/sbin/amixer -D pulse sset Master toggle"
    m:0x10 + c:121
    Mod2 + XF86AudioMute

Offline

#22 2014-11-03 08:37:53

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,343
Website

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

@jdevelop-this script does not require alsautils and was designed to function completely with pulseaudio native utils.  See this comment.

Last edited by graysky (2014-11-03 10:07:23)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#23 2014-11-03 09:31:20

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,343
Website

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

New with version 1.45-1 is support to push notifications through libnotify.  Please check ~/.config/pulseaudio-ctl/config against the provided /usr/share/pulseaudio-ctl/config.skel to ensure it is current as the script does not do this automatically.

% cat ~/.config/pulseaudio-ctl/config
#
# $HOME/.config/pulseaudio-ctl/pulseaudio-ctl.conf
#

# The default setting is for pulseaudio-ctl to NOT increase to volume level
# above 100 % but Some users may wish exceed this level. If this describes
# your use case, uncomment the UPPER_THRESHOLD variable below setting it to
# the new upper threshold.
# 
#UPPER_THRESHOLD=150

# Push output through libnotify. Set to any value to enable this feature
# and note that you must have /usr/bin/notify-send to use this. On Arch
# libnotify provides this. Other distros may not name it as such.
NOTIFY=yes

CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#24 2014-11-10 06:55:00

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

@graysky

Great improvement to provide notifications, thanks!

Can they be tweaked to look more like the ones from Xfce4 Volume Manager, which I find produces very simple but appealing messages?

Example: http://i.imgur.com/7Hx89mk.png

Offline

#25 2014-11-25 00:08:13

emacsomancer
Member
Registered: 2014-09-20
Posts: 136

Re: pulseaudio-ctl: vol+/- and mute from the shell or shortcut keys

orschiro wrote:

@graysky

Thanks for this promising script! I am wondering why it does not recognise my running pulseaudio session?

~ /usr/bin/pulseaudio-ctl mute
No PulseAudio daemon running, or not running as session daemon.
No PulseAudio daemon running, or not running as session daemon.
No PulseAudio daemon running, or not running as session daemon.
No PulseAudio daemon running, or not running as session daemon.
No PulseAudio daemon running, or not running as session daemon.
No PulseAudio daemon running, or not running as session daemon.
 Cannot find current volume. CURVOL = 
~ ps aux | grep pulse
orschiro 27720  0.0  0.0 352948  6264 ?        SNl  20:23   0:00 pulseaudio --start
orschiro 27746  0.0  0.0  76484  2716 ?        SN   20:24   0:00 /usr/lib/pulse/gconf-helper

I'm having this same problem - when I try to connect to the autostarted pulseaudio daemon.  I have to kill pulseaudio and restart it manually from the commandline - and then it works. Any workaround for this? (Other than having to manually do it on every boot? Will adding a line to my .xinitrc work?)

Offline

Board footer

Powered by FluxBB