Skip to content

Instantly share code, notes, and snippets.

@Monsterovich
Last active July 17, 2021 06:22
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Monsterovich/15f495e4d1ec9a37c8b590acc9139d78 to your computer and use it in GitHub Desktop.
Save Monsterovich/15f495e4d1ec9a37c8b590acc9139d78 to your computer and use it in GitHub Desktop.
Pipewire headphone jack fix
#!/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