I want to detect whether the screensaver is active. On Ubuntu 14.04 and Fedora 21, I tried the following command:

$ dbus-send --print-reply=literal --dest=org.freedesktop.ScreenSaver /org/freedesktop/ScreenSaver org.freedesktop.ScreenSaver.Lock
Error org.freedesktop.DBus.Error.NotSupported: This method is not implemented

I'm probably misunderstanding dbus-send as d-feet shows me that the method GetActive is available.

d-feet screenshot

How can I detect screensaver activity, preferably in a desktop independent manner? There is a related question, which however wasn't solved.

  • In my enviroment (KDE 4 on Fedora 21), your dbus-send command starts a screensaver. – marbu Apr 22 '15 at 8:15
  • @marbu Interesting! I guess there is something wrong with my command - question is, what? – Thomas W. Apr 22 '15 at 10:05

You aren't misunderstanding dbus-send.

It's just that Gnome-Shell is lying. That means a Gnome-Shell developer literally took the KDE API description as-is and only implemented the 2 methods that are part of the freedesktop idle inhibition specification. Other methods thus return with unimplemented error:

+        } else if (g_strcmp0 (method_name, "GetActive") == 0) {
+                goto unimplemented;
+        } else ...

Review comments that considered this approach being confusing were ignored.

This is still the status quo with Gnome-Shell 3.38.1 (e.g. on Fedora 33):

$ qdbus org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.GetActive
Error: org.freedesktop.DBus.Error.NotSupported
This method is not implemented
$ qdbus org.freedesktop.ScreenSaver /org/freedesktop/ScreenSaver org.freedesktop.ScreenSaver.GetActive
Error: org.freedesktop.DBus.Error.NotSupported
This method is not implemented

Thus, your best approach is to try multiple methods until you don't get an NotSupported error back.

For example to check for Gnome-Shell:

$ qdbus org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.GetActive                
| improve this answer | |
  • Great! I found gnome-screensaver-command --query seems to work as well, but it prints a localized textual message which is much less convenient. – Thomas W. Nov 16 at 12:36
  • @ThomasW. using LC_ALL=C gnome-screensaver-command --query perhaps helps with the localization (haven't tested it as I don't have that command installed) – maxschlepzig Nov 16 at 12:53
  • Of course it would, but who knows if the wording of the message might be changed at some point? A true/false value if much better. – Thomas W. Nov 16 at 15:54

Depending on your environment:

$ qdbus org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.GetActive

$ qdbus org.kde.screensaver /ScreenSaver org.freedesktop.ScreenSaver.GetActive

$ qdbus org.gnome.ScreenSaver /ScreenSaver org.gnome.ScreenSaver.GetActive

The correct one should give a true or false statement. The incorrect one will give an error.

$ qdbus org.gnome.ScreenSaver /ScreenSaver org.gnome.ScreenSaver.GetActive

$ qdbus org.kde.screensaver /ScreenSaver org.freedesktop.ScreenSaver.GetActive
Service 'org.kde.screensaver' does not exist.

(I'm running Gnome)

| improve this answer | |
  • I'm running Gnome and the Gnome command returns false even when my screensaver is enabled. – Cerin Oct 3 '16 at 22:37
  • And would you like to mention what version of Gnome? – Ken Sharp Oct 14 '16 at 19:23
  • With Gnome-Shell 3.38.1, your org.gnome.ScreenSaver examples don't work, i.e. I have to use /org/gnome/ScreenSaver as second argument instead of /ScreenSaver. – maxschlepzig Nov 16 at 10:25
  • No real surprise that Gnome 3 is different to Gnome 2. I dropped Gnome long ago. – Ken Sharp Nov 22 at 4:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.