Detect when screensaver is activated?
#1
I'm looking to run a service that detects when the screensaver activates after which commands will be executed. I'm not quite sure how to implement this, here's my attempt. Can anyone point out what I'm missing? I see the screensaver activation in the debug logging but the script isn't detecting it.

Code:
import time
import xbmc

if __name__ == '__main__':
    monitor = xbmc.Monitor()

    while not monitor.abortRequested():

        xbmc.log("service.test heartbeat %s" % time.time(), level=xbmc.LOGDEBUG)

        # Sleep/wait for abort for 10 seconds
        if monitor.waitForAbort(10):
            # Abort was requested while waiting. We should exit
            break

        def onScreensaverActivated(self):
            xbmc.log("service.test screensaver activated %s" % time.time(), level=xbmc.LOGDEBUG)
Reply
#2
I'm guessing the screensaver activation happens when I'm waiting for 10 seconds. I'm not sure how to always be listening for it.
Reply
#3
You want something more like:
Code:
import time

import xbmc

class MyMonitor(xbmc.Monitor):
    def onScreensaverActivated(self):
        xbmc.log("service.test screensaver activated %s" % time.time(), level=xbmc.LOGDEBUG)

monitor = MyMonitor()
while not monitor.abortRequested():
    if monitor.waitForAbort(10):
        # Abort was requested while waiting. We should exit
        break

    xbmc.log("service.test heartbeat %s" % time.time(), level=xbmc.LOGDEBUG)
Reply
#4
That did the trick, thank you!
Reply
#5
You might want to take a look here for ideas (or maybe just to use it).
Reply
#6
(2016-01-18, 16:15)trogggy Wrote: You might want to take a look here for ideas (or maybe just to use it).

Thanks trogggy, I'll take a look today. I'm actually trying to do something pretty specific and I'm almost there. I'll post where I'm at and the last bit I need to complete it next.
Reply
#7
This goal of this service is to log out of the current profile when the screensaver is activated. There are a couple of addons out there that do something similar but I had a few goals in mind.

- Ignore logoff if audio is playing
- Stop video playback (in case video is paused when the screensaver kicks in)
- Start the default screensaver after logging off
- Give a buffer and abort the logoff if the screensaver is deactivated within a variable amount of time (60 seconds in the example below)

Everything is working as expected except I can't figure out how to send an abort when the screensaver is deactivated so I can abort the logoff sequence.

Code:
import time
import xbmc

class ssOnMonitor(xbmc.Monitor):
    def onScreensaverActivated(self):
        xbmc.log("service.logoff screensaver activated %s" % time.time(), level=xbmc.LOGDEBUG)

        if not xbmc.Player().isPlayingAudio():
            monitor2 = ssOffMonitor()
            while not monitor2.abortRequested():
                if monitor2.waitForAbort(60):
                    # Abort was requested while waiting. We should exit
                    break
                xbmc.executebuiltin("PlayerControl(Stop)")
                xbmc.executebuiltin("System.Logoff()")
                xbmc.executebuiltin("ActivateScreensaver()")

class ssOffMonitor(xbmc.Monitor):
    def onScreensaverDeactivated(self):
        xbmc.log("service.logoff screensaver deactivated %s" % time.time(), level=xbmc.LOGDEBUG)
        # How do I send an abort? Logoff should be aborted.

monitor1 = ssOnMonitor()
while not monitor1.abortRequested():
    if monitor1.waitForAbort(10):
        # Abort was requested while waiting. We should exit
        break
Reply

Logout Mark Read Team Forum Stats Members Help
Detect when screensaver is activated?0