Skip to content

Instantly share code, notes, and snippets.

Last active July 15, 2020 23:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
#!/bin/env python
# cyclesink sets all audio sources (sink inputs) to the same next
# sink in PulseAudio. PulseAudio sets newly created sink inputs to
# use the sink that was last assigned to, so all sources should always
# be using the same output unless the configuration is changed elsewhere.
import os
def get_sinks():
stream = os.popen('pactl list short sinks')
output =
sinks = []
for sink in output.splitlines():
sink_no = sink.split()[0]
sink_name = sink.split()[1]
'no': sink_no,
'name': sink_name,
return sinks
def get_streams():
stream = os.popen('pactl list short sink-inputs')
output =
streams = []
for stream in output.splitlines():
stream_no = stream.split()[0]
sink_no = stream.split()[1]
'no': stream_no,
'sink': sink_no,
return streams
streams = get_streams()
sinks = get_sinks()
if len(streams) == 0:
print('no streams')
if len(sinks) == 0:
print('no sinks')
# if only one sink, just set all streams to it
cur = streams[0]['sink']
idx = 0
for i, sink in enumerate(sinks):
if sink['no'] == cur:
print('found sink idx:', i)
idx = i
nxt = sinks[(idx+1)%len(sinks)]
for stream in streams:
print('setting {} to {}'.format(stream['no'], nxt['no']))
os.popen('pactl move-sink-input {} {}'.format(stream['no'], nxt['no']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment