Disengaging screensavers from script?

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
hwbehrens
Posts: 19
Joined: Fri Mar 19, 2010 9:10 pm

Disengaging screensavers from script?

Post by hwbehrens » Wed May 25, 2011 5:20 pm

Does anyone know of a way to 'wake' from a screensaver/energy saver using script?

The situation is such that I can't (a) expect the user to wake it manually via mouse or keyboard, and (b) I can't modify the user's screensaver preferences.

My first thought was wiggling the mouse using screenMouseLoc, but that doesn't work on either Mac or Windows. I found some VB scripts that Rev could theoretically execute that might solve my problem on Windows, but I'm still stuck on the Mac.

Any ideas?

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Disengaging screensavers from script?

Post by Klaus » Wed May 25, 2011 5:41 pm

Hi hwbehrens,

put this into a field or custom property:

try
tell application id "com.apple.ScreenSaver.Engine" to quit
end try

and then "do" this string as AppleScript :D

Just tested with a button and works:

Code: Select all

on mouseUp
  send "do_as" to me in 5 secs
  ## So I have time to activate that thing :-)
end mouseUp

command do_as
  do fld 1 as "AppleScript"
end do_as

Best from germany

Klaus

hwbehrens
Posts: 19
Joined: Fri Mar 19, 2010 9:10 pm

Re: Disengaging screensavers from script?

Post by hwbehrens » Wed May 25, 2011 7:43 pm

Excellent, thanks!

hwbehrens
Posts: 19
Joined: Fri Mar 19, 2010 9:10 pm

Re: Disengaging screensavers from script?

Post by hwbehrens » Wed May 25, 2011 11:13 pm

I'm actually having trouble getting this to work on 10.6.7. Which version are you running the example on?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Disengaging screensavers from script?

Post by bn » Wed May 25, 2011 11:36 pm

Hi hw,

did you put
try
tell application id "com.apple.ScreenSaver.Engine" to quit
end try
into the only field on the card? Or the field with the lowest layer?

Maybe you rename the field and call it by name in the button script. Should work.

Klaus's beautiful script works right away for me on MacOSX 10.6.7

Kind regards

Bernd

hwbehrens
Posts: 19
Joined: Fri Mar 19, 2010 9:10 pm

Re: Disengaging screensavers from script?

Post by hwbehrens » Wed May 25, 2011 11:41 pm

Yes, as far as I can tell, everything is correct. I have a beep just above the "do as ..." line, so I know it's getting to it, but it's not actually exiting the screensaver.

I am triggering the screensaver using the Test button the Desktop & Screen Saver prefpane. Are you doing the same, or using Hot Corners?

EDIT: Yes, I tried it with Hot Corners and it works. Apparently the "Test" button invokes the screensaver in such a way that the script doesn't work properly.

EDIT 2: Okay, here is an alternative Applescript that works for normally-invoked and Test-invoked screensavers as well as for displays which have gone to sleep:

Code: Select all

try
tell application "System Events" to key code 59
end try
Certainly not as clean or elegant, but it gets the job done. Key code 59 is CTRL, so it doesn't pollute any of my fields with errant characters thankfully.

hwbehrens
Posts: 19
Joined: Fri Mar 19, 2010 9:10 pm

Re: Disengaging screensavers from script?

Post by hwbehrens » Thu May 26, 2011 1:02 am

I'm still struggling with the VBScript implementation. From what I can tell, I need to use the following command:

Code: Select all

SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 1);
However, because I have no experience with VBScript at all, I'm not even sure if that's a valid command. Do I need to wrap it in a function name? I just keep getting execution errors as my 'do' result...

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Disengaging screensavers from script?

Post by SparkOut » Thu May 26, 2011 1:19 am

That doesn't look at all like VBScript - either C++ or C# I think.

The problem with waking from screensaver is that many systems will be set to lock when the screensaver triggers. On waking, the login screen will be presented, causing the user to manually rejoin the logged in session.

The best I can suggest is this: http://blogs.technet.com/b/heyscripting ... rting.aspx

to prevent the screensaver kicking in in the first place.

hwbehrens
Posts: 19
Joined: Fri Mar 19, 2010 9:10 pm

Re: Disengaging screensavers from script?

Post by hwbehrens » Thu May 26, 2011 4:09 pm

Yeah, I realize what I'm trying to do is not an ideal solution. I'm not as worried about the password prompt, as that would imply that they have a mouse and/or a keyboard attached. However, many of our users are running our software as a kiosk without any form of (traditional) input attached.

If they forget to disable their screensaver during the initial installation, they won't be able to get out of it once it starts without connecting a keyboard or mouse.

Ideally, the software would honor their screensaver settings and wake only at predetermined times (when the software receives input over a socket, for example), but if the only solution is to disable the screensaver completely, that will be better than what we have today.

hwbehrens
Posts: 19
Joined: Fri Mar 19, 2010 9:10 pm

Re: Disengaging screensavers from script?

Post by hwbehrens » Thu May 26, 2011 5:11 pm

After reading the article, it seemed as if these lines are what actually wake the computer:

Code: Select all

Set objIE = CreateObject("InternetExplorer.Application")
Wscript.Sleep 1000
objIE.Quit
If I put those lines into a .vbs, they execute fine, but if I load them from a field and "do as" them, I get an execution error. Is there some trick to formatting VBScript commands for Livecode to execute them properly?

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Disengaging screensavers from script?

Post by SparkOut » Thu May 26, 2011 6:52 pm

From the dictionary under "do"
Any scripts on Windows which contain references to WScript will fail to run as WScript objects do not exist in the LiveCode Environment. Return values should therefore be placed within the global result variable instead of using WScript.Echo.
So you could handle this in an alternative manner by having the vbscript file saved externally to the Livecode application, and use the 'get shell' method of execution and result retrieval.
A recent thread http://forums.runrev.com/phpBB2/viewtop ... 000#p35000 showed the technique in action.

hwbehrens
Posts: 19
Joined: Fri Mar 19, 2010 9:10 pm

Re: Disengaging screensavers from script?

Post by hwbehrens » Thu May 26, 2011 8:07 pm

Thanks for the tip! I'm not sure how I missed that. I am going to see if I can find a solution that doesn't require WScript objects first so I can continue to use the 'do as' method, but if I don't have any luck, I'll definitely go with the local vbs execution method.

Thanks again!

Post Reply