Created
April 9, 2024 20:19
-
-
Save hadrianw/2048b722442e2c717d7277dcb338d1ad to your computer and use it in GitHub Desktop.
Minimal notification service for Avahi services
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 | |
""" | |
example use: | |
./avahi-notify.py - notify for all interfaces | |
./avahi-notify.py eth0 - notify only for eth0 interface | |
""" | |
import io | |
import subprocess | |
import sys | |
if __name__ == "__main__": | |
ifaces = sys.argv[1:] | |
avahi = subprocess.Popen(["avahi-browse", "-pa"], stdout=subprocess.PIPE) | |
for line in io.TextIOWrapper(avahi.stdout, encoding="utf-8"): | |
(state, iface, proto, name, stype, domain) = line.split(";") | |
if ifaces and iface not in ifaces: | |
continue | |
icon = () | |
if state == "+": | |
icon = ("-i", "list-add") | |
title = f"Connected {stype} ({proto})" | |
elif state == "-": | |
icon = ("-i", "list-remove") | |
title = f"Disconnected {stype} ({proto})" | |
p = subprocess.run(("notify-send", *icon, title, name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment