11

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.

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

2 Answers 2

3

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
false

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

(I'm running Gnome)

5
  • I'm running Gnome and the Gnome command returns false even when my screensaver is enabled.
    – Cerin
    Commented Oct 3, 2016 at 22:37
  • 1
    And would you like to mention what version of Gnome?
    – Ken Sharp
    Commented Oct 14, 2016 at 19:23
  • 3
    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. Commented Nov 16, 2020 at 10:25
  • No real surprise that Gnome 3 is different to Gnome 2. I dropped Gnome long ago.
    – Ken Sharp
    Commented Nov 22, 2020 at 4:10
  • qdbus org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.GetActive also only returns "Service 'org.gnome.ScreenSaver' does not exist." with 3.28.3 (RHEL7)
    – Rich
    Commented Mar 31, 2021 at 21:15
2

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                
false
3
  • 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.
    Commented Nov 16, 2020 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) Commented Nov 16, 2020 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.
    Commented Nov 16, 2020 at 15:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .