dotfiles

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 9bc008d19aed81a431880a47b7d58da28ab6df2b
parent 885443443c9b1962030771003b505732a0acdcfe
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Sat, 22 Jan 2022 00:34:57 +0200

Add the audio output flipper script.

Diffstat:
Abin/pulseaudio-sink-port-flip | 47+++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+), 0 deletions(-)

diff --git a/bin/pulseaudio-sink-port-flip b/bin/pulseaudio-sink-port-flip @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 + +from subprocess import Popen, PIPE + + +def get_current_active_port() -> str: + pactl_list_sinks = Popen(["pactl", "list", "sinks"], stdout=PIPE) + + output, stderr = pactl_list_sinks.communicate() + + current_active_port = None + for line in output.decode().split("\n"): + if "Active Port:" in line: + current_active_port = line.split(": ")[1].strip() + + return current_active_port + + +def main() -> None: + current_active_port = get_current_active_port() + print("Current active port:", current_active_port) + + if current_active_port == "analog-output-headphones": + Popen( + [ + "pactl", + "set-sink-port", + "alsa_output.pci-0000_00_1f.3.analog-stereo", + "analog-output-speaker", + ] + ).wait() + elif current_active_port == "analog-output-speaker": + Popen( + [ + "pactl", + "set-sink-port", + "alsa_output.pci-0000_00_1f.3.analog-stereo", + "analog-output-headphones", + ] + ).wait() + + current_active_port = get_current_active_port() + print("New current active port:", current_active_port) + + +if __name__ == "__main__": + main()