Prevent ScreenSaver and/or Sleep - Windows

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
newpie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 155
Joined: Sat Jun 29, 2013 11:24 pm

Prevent ScreenSaver and/or Sleep - Windows

Post by newpie » Wed Aug 02, 2017 3:05 pm

Hello, I am looking to prevent sleep and/or screensaver on Windows 10 based computer without admin privileges. I found an older post below http://forums.livecode.com/viewtopic.php?f=9&t=671 with the following for MAC.

1. Does the below code still apply?
2. Can I use it for Windows?
3. Does it also prevent screensaver coming up (after inactivity)

Thanks for any help

Code: Select all

function sleepTime
  return shell("pmset -g | grep displaysleep | awk '{ print $2; }'")
end sleepTime

on setSleepTime theMins
  ask "Enter your password"
  if it is not empty then
    put it into myPW
    put "#!/bin/sh" & cr into myScript
    put "pw=" & quote & myPW & quote & cr after myScript
    put "echo $pw | sudo pmset dim " & theMins & cr after myScript
    put myscript
    put shell(myScript) into rslt  -- do the command & get the result
    if rslt is not empty then
      beep
      answer error "Sorry, a problem occurred." & cr & cr & rslt with "Okay"
    end if
  end if
end setSleepTime

on setSleepTimeAS theMins
  put "sudo pmset dim " & theMins into myShell
  put "try" & cr & ¬
  "do shell script" && quote & myShell & quote && "with administrator privileges" & cr & ¬
  "on error myErr number myErrNr" & cr & ¬
  "set myErrMsg to myErr & ' (' & myErrNr & ')'" & cr & ¬
  "end try" into myScript
  replace "'" with quote in myScript
  do myScript as AppleScript
  put the result into rslt
  if rslt is not empty and rslt is not (quote & quote) and "(-128)" is not in rslt then
    beep
    answer error "Sorry, a problem occurred." & cr & cr & rslt with "Okay"
  end if
end setSleepTimeAS

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Prevent ScreenSaver and/or Sleep - Windows

Post by mrcoollion » Wed Aug 02, 2017 4:45 pm

Hello newpie,

To prevent the screensaver from kicking in you might want to try a routine that moves the mouse a pixel every # seconds.

Alternatively in windows you could push a shell command to set a registry setting.
Do not know if this works the same for the Window version you need it for and also if your user has the correct permissions to do this.
https://securityblog.gr/1910/disable-sc ... mand-line/

Experiment but be careful with registry settings (always backup).

regards,

Paul

Post Reply

Return to “Talking LiveCode”