Created
June 22, 2018 20:52
-
-
Save rif/01ffb5e3eb45d2e4e6ebb4652b3b19ce to your computer and use it in GitHub Desktop.
Revisions
-
rif created this gist
Jun 22, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ #!/usr/bin/env python3 from subprocess import check_output from re import findall, DOTALL, MULTILINE inputs = findall(r'.*?index: (\d+).*?sink: (\d+).*?application\.process\.id = "(\d+)"', check_output(['pacmd', 'list-sink-inputs']).decode("utf-8"), DOTALL|MULTILINE) sinks = findall(r'index: (\d+)', check_output(['pacmd', 'list-sinks']).decode("utf-8")) focused_window = check_output(['xdotool', 'getwindowfocus']) focused_pid = check_output(['xdotool', 'getwindowpid', focused_window]).strip().decode("utf-8") for app in inputs: if app[2] == focused_pid: # find new sink index index = 0 for i in range(len(sinks)): if sinks[i] == app[1]: index = (i + 1) % len(sinks) # rotation break check_output(['pacmd', 'move-sink-input', app[0], sinks[index] ]) break