Skip to content

Instantly share code, notes, and snippets.

@rcassani
Created October 31, 2017 16:36
Show Gist options
  • Save rcassani/3846ca2edbfbff41d8f9773a4e5ccda2 to your computer and use it in GitHub Desktop.
Save rcassani/3846ca2edbfbff41d8f9773a4e5ccda2 to your computer and use it in GitHub Desktop.
Program to toggle aming the available audio output devices
#!/usr/bin/python3
'''
Toggle the audio output devices among the available
'''
import pulsectl
def main():
pulse = pulsectl.Pulse('my-client')
# Create list of sink objects
sinks = pulse.sink_list()
# Find current sink, old_sink in sinks
old_sink_name = pulse.server_info().default_sink_name
for sink in sinks:
if sink.name == old_sink_name:
i_sink = sinks.index(sink)
break
if len(sinks) >= 2:
i_sink = i_sink + 1
if i_sink >= len(sinks):
i_sink = 0
# Set new_sink as default sink
pulse.sink_default_set(sinks[i_sink].name)
# Move streams, sink_inputs to new sink
for sink_input in pulse.sink_input_list():
pulse.sink_input_move(sink_input.index, sinks[i_sink].index)
pulse.disconnect()
print(sinks[i_sink].port_active.description + ' in ' + sinks[i_sink].description )
return
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment