コード例 #1
0
ファイル: config.py プロジェクト: shizonic/my-machines
def switch_pulse_default(prop):
    pulse = Pulse('qtile')
    current_default = getattr(pulse.server_info(),
                              'default_{}_name'.format(prop))

    set_next = False
    things = getattr(pulse, '{}_list'.format(prop))()
    for thing in itertools.chain(things, things):
        if set_next:
            notify("Sound", "Default {} to {}".format(prop, thing.name))
            pulse.default_set(thing)
            break
        elif thing.name == current_default:
            set_next = True

    if prop == 'sink':
        list_cmd = 'list-sink-inputs'
        move_cmd = 'move-sink-input'
    else:
        list_cmd = 'list-source-outputs'
        move_cmd = 'move-source-output'

    streams = subprocess.getoutput(
        "pacmd {} | grep index | awk '{{ print $2 }}'".format(list_cmd))
    streams = [int(idx.strip()) for idx in streams.splitlines()]

    for stream in streams:
        cmd = "pacmd {cmd} {stream_id} {thing_id}".format(cmd=move_cmd,
                                                          stream_id=stream,
                                                          thing_id=thing.index)
        print(cmd)
        subprocess.check_call(shlex.split(cmd))
コード例 #2
0
#! /usr/bin/env python

from pulsectl import Pulse
import subprocess

pulse = Pulse('audio-sink-chooser')

sinks = pulse.sink_list()
choices = ""
for sink in sinks:
    choices = choices + sink.description + '\n'

p = subprocess.run(['rofi', '-dmenu'],
                   input=choices,
                   encoding='ascii',
                   stdout=subprocess.PIPE)
choice = str(p.stdout).strip()
choosensink = next(sink for sink in sinks if sink.description == choice)
pulse.default_set(choosensink)

inputs = pulse.sink_input_list()

for ainput in inputs:
    pulse.sink_input_move(ainput.index, choosensink.index)