Created
January 13, 2024 15:03
-
-
Save jepler/ff55a475e9c90c8b1b7f00707799565c to your computer and use it in GitHub Desktop.
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/python | |
import pulsectl | |
def default_source(pulse): | |
default_source_name = pulse.server_info().default_source_name | |
for source in pulse.source_list(): | |
if source.name == default_source_name: | |
return source | |
return None | |
def update_led(pulse): | |
if source := default_source(pulse): | |
with open( | |
"/sys/devices/platform/thinkpad_acpi/leds/platform::micmute/brightness", | |
"w", | |
) as f: | |
print(source.mute, file=f) | |
while True: | |
try: | |
with pulsectl.Pulse("event-printer") as pulse: | |
def stop_after_one_event(ev): | |
raise pulsectl.PulseLoopStop | |
pulse.event_mask_set("source") | |
pulse.event_callback_set(stop_after_one_event) | |
while True: | |
update_led(pulse) | |
pulse.event_listen(timeout=None) | |
except pulsectl.PulseDisconnected as e: | |
print("Reconnecting") | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment