-
-
Save fatihkaan22/9f714c48750ef08cf55cfaeca85b574c to your computer and use it in GitHub Desktop.
Pipewire headphone jack fix - also switch input source
This file contains hidden or 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\"") # speaker | |
os.system("pactl set-source-port 0 \"analog-input-headset-mic\"") # microphone | |
sys.stdout.write("Headphones plugged in\n") | |
elif (action == "unplug"): | |
os.system("pactl set-sink-port 0 \"analog-output-speaker\"") # speaker | |
os.system("pactl set-source-port 0 \"analog-input-internal-mic\"") # microphone | |
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