ActiveState Code

Recipe 576828: Run screensaver from Python


Simple script that will allow you to locate and run the set screensaver from python, if available.

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import os, win32com.client

def runScreensaver():
    strComputer = "."
    objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
    objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
    colItems = objSWbemServices.ExecQuery("Select * from Win32_Desktop")
    for objItem in colItems:
        if objItem.ScreenSaverExecutable:
            os.system(objItem.ScreenSaverExecutable + " /start")
            break

Sign in to comment