Created
May 27, 2024 16:48
-
-
Save LevitatingBusinessMan/85c600f20cb55479f9b52de78323b9d5 to your computer and use it in GitHub Desktop.
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 ruby | |
require "dbus" | |
system_bus = DBus::SystemBus.instance | |
session_bus = DBus::SessionBus.instance | |
$networkd_service = system_bus.service("org.freedesktop.network1") | |
$networkd_object = $networkd_service.object("/org/freedesktop/network1") | |
$networkd_properties = $networkd_object["org.freedesktop.DBus.Properties"] | |
$networkd_manager = $networkd_object["org.freedesktop.network1.Manager"] | |
def listen name, object | |
$networkd_service.object(object)["org.freedesktop.DBus.Properties"].on_signal("PropertiesChanged") do |iface, props, inv_props| | |
puts "Property change on #{name}: #{props}" | |
notify name, props["OnlineState"] if props.include? "OnlineState" | |
end | |
end | |
def notify name, state | |
`notify-send "Link #{name} is #{state}"` | |
end | |
$networkd_properties.on_signal("PropertiesChanged") do |iface, props, inv_props| | |
# Listen on the generic /network object | |
puts "Generic change for #{iface}: #{props}" | |
end | |
for index, name, object in $networkd_manager.ListLinks[0] | |
listen name, object | |
end | |
main = DBus::Main.new | |
main << system_bus | |
main.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment