Created
February 23, 2013 03:05
-
-
Save oz/5018170 to your computer and use it in GitHub Desktop.
Detecting screensaver state in Ruby with DBus...
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/env ruby | |
# encoding: utf-8 | |
require 'time' | |
require 'dbus' | |
main = DBus::Main.new | |
trap("INT") { | |
puts "Quitting..." | |
main.quit | |
exit | |
} | |
bus = DBus.session_bus | |
saver = bus.service("org.gnome.ScreenSaver").object("/org/gnome/ScreenSaver") | |
saver.introspect | |
saver.default_iface = 'org.gnome.ScreenSaver' | |
saver.on_signal("ActiveChanged") do |state| | |
str = state ? 'activated' : 'deactivated' | |
puts "[#{ Time.now } ] Screensaver has been #{ str }." | |
end | |
main << bus | |
main.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment