Skip to content

Instantly share code, notes, and snippets.

@jpetazzo
Created January 7, 2012 22:24
Show Gist options
  • Save jpetazzo/1576273 to your computer and use it in GitHub Desktop.
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
#!/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