1
0
mirror of https://github.com/frebib/dotfiles.git synced 2024-06-14 12:57:23 +00:00
dotfiles/i3/cycleaudio.py
Joe Groocock 60bf423556
dotfiles: move .config/* to root
This seems to make more sense. Almost all files were within .config
anyway.

Signed-off-by: Joe Groocock <me@frebib.net>
2020-08-10 22:42:14 +01:00

32 lines
983 B
Python
Executable File

#!/usr/bin/env python3
import subprocess as sp
import re
# This script cycles pulseaudio sinks and changes the defaults.
# Audio playback is also moved to the new default sink. The script
# is intended to bind to some keyboard shortcut to cycle through
# outputs on the fly.
#
# Requirements: pacmd, python3
dev_out, _ = sp.Popen('pacmd list-sinks', shell=True, stdout=sp.PIPE).communicate()
inp_out, _ = sp.Popen('pacmd list-sink-inputs', shell=True, stdout=sp.PIPE).communicate()
devices = re.findall(r"(\*?) index: (\d+)", str(dev_out))
inputs = re.findall(r"index: (\d+)", str(inp_out))
# find the next default device, i.e., the one after the current default
found = False
next_device = devices[0][1]
for d in devices:
if found:
next_device = d[1]
break
found = (d[0] == "*")
# set default device and move inputs
sp.call(["pacmd", "set-default-sink", next_device])
for i in inputs:
sp.call(["pacmd", "move-sink-input", i, next_device])