Created
January 7, 2012 22:24
-
-
Save jpetazzo/1576273 to your computer and use it in GitHub Desktop.
Little script that I use to change the Pulseaudio volume with my keyboard bindings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import commands, sys, os | |
padump = commands.getoutput('pacmd dump').split('\n') | |
if sys.argv[1]=='toggle': | |
for muteline in padump: | |
if 'set-sink-mute' in muteline: | |
cmd, src, val = muteline.split() | |
val = {'yes':'no', 'no':'yes'}[val] | |
os.system('pacmd {cmd} {src} {val} >/dev/null'.format(**locals())) | |
else: | |
for volline in padump: | |
if 'set-sink-volume' in volline: | |
cmd, src, vol = volline.split() | |
vol = int(vol,16) | |
if sys.argv[1][0] in "-+": | |
vol += int(sys.argv[1]) | |
else: | |
vol = int(sys.argv[1]) | |
if vol<0: vol=0 | |
if vol>65535: vol=65535 | |
os.system('pacmd {cmd} {src} {vol} >/dev/null'.format(**locals())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment