5

Has the method to get the session idle time through dbus changed in the recent Ubuntu or my dbus code here is wrong?

#!/usr/bin/env python

import dbus

bus_name = 'org.gnome.ScreenSaver'
obj_path = '/org/gnome/ScreenSaver'

session_bus = dbus.SessionBus()
gs_obj = session_bus.get_object(bus_name, obj_path)
gs_iface = dbus.Interface(gs_obj, bus_name)

print gs_iface.GetSessionIdleTime()

# dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownMethod: No such method 'GetSessionIdleTime'

Reference:
https://people.gnome.org/~mccann/gnome-screensaver/docs/gnome-screensaver.html#gs-method-GetSessionIdleTime

Flint
  • 3,121
  • 5
  • 27
  • 50

2 Answers2

1

This is a old question, but I was looking for a similar solution for Gnome3. Only tested on Ubuntu 20.04 with Python 3.8.5.

import dbus
    
session_bus = dbus.SessionBus()
bus_object = session_bus.get_object('org.gnome.Mutter.IdleMonitor', '/org/gnome/Mutter/IdleMonitor/Core')
bus_interface = dbus.Interface(bus_object, 'org.gnome.Mutter.IdleMonitor')
print(bus_interface.GetIdletime() / 1000)
Sander88
  • 11
  • 1
0

That was in Gnome2, The reference you have mentioned is for gnome-screensaver version 2.15.3.

Even back to Ubuntu 12.04, it contains version 3.4.1! That seems it had been removed. Check newer doc.

Hint: You can use d-feet a D-Bus viewer and debugger. To see/browse all running services and all available methods, signals & properties.

user.dz
  • 47,137
  • 13
  • 140
  • 258
  • But the question remains in Ubuntu 16.04 Unity DM today... How do you get gnome inactive time? The OP question is still relevant because after watching movie for 10 minutes on Monitor #2 I want to dim Monitor #1 and Monitor #3 with a script. I plan to use the same script with Ubuntu 20.04 next year. – WinEunuuchs2Unix Jun 17 '19 at 01:39