Created
July 13, 2011 09:16
-
-
Save exhuma/1079972 to your computer and use it in GitHub Desktop.
Linking (un)loading of your SSH private keys with your screensaver state
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
import dbus.mainloop.glib | |
import gobject | |
from subprocess import Popen | |
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) | |
def screensaver_state_changed(new_state): | |
if new_state: | |
# screen saver changed state to "active" | |
Popen(["/usr/bin/keychain", "--clear"]).communicate() | |
else: | |
# screen saver changed state to "inactive" | |
Popen(["/usr/bin/keychain", "/path/to/private/key"]).communicate() | |
BUS = dbus.SessionBus() | |
PROXY = BUS.get_object( | |
'org.kde.screensaver', | |
'/ScreenSaver' | |
) | |
PROXY.connect_to_signal( | |
'ActiveChanged', | |
screensaver_state_changed, | |
dbus_interface = 'org.freedesktop.ScreenSaver') | |
loop = gobject.MainLoop() | |
loop.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment