Skip to content

Instantly share code, notes, and snippets.

@oz
Created February 23, 2013 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oz/5018170 to your computer and use it in GitHub Desktop.
Save oz/5018170 to your computer and use it in GitHub Desktop.
Detecting screensaver state in Ruby with DBus...
#!/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