-
-
Save thenonameguy/94151cc33867d2d1eabaea6151a6a6d1 to your computer and use it in GitHub Desktop.
NixOS 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(["/run/current-system/sw/sbin/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"): | |
# must have `pulseaudio` pkg installed | |
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