Last active
July 17, 2021 06:22
-
-
Save Monsterovich/15f495e4d1ec9a37c8b590acc9139d78 to your computer and use it in GitHub Desktop.
Pipewire headphone jack fix
This file contains 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 characters
#!/usr/bin/env python | |
import os | |
import sys | |
from subprocess import Popen, PIPE, STDOUT | |
import time | |
HEADPHONE_EVENT = "jack/headphone" | |
p = Popen(["/usr/bin/acpi_listen"], | |
stdout=PIPE, stderr=STDOUT, bufsize=1) | |
with p.stdout: | |
for line in iter(p.stdout.readline, b''): | |
event = line.decode("utf-8").split(' ') | |
if event[0] == HEADPHONE_EVENT: | |
action = event[2].strip() | |
time.sleep(0.5) | |
if (action == "plug"): | |
os.system("pactl set-sink-port 0 \"analog-output-headphones\"") | |
sys.stdout.write("Headphones plugged in\n") | |
elif (action == "unplug"): | |
os.system("pactl set-sink-port 0 \"analog-output-speaker\"") | |
sys.stdout.write("Headphones plugged out\n") | |
sys.stdout.flush() | |
p.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment