PDA

View Full Version : Scripting Screensaver




bravencarver
Apr 22, 2011, 12:10 PM
Hello all!

So here is my dilemma, I'm connecting an iPad to a mac mini via an app called Screens which uses VNC. When a computer is connected via VNC it doesn't want to go to sleep or activate screensaver. Well I need that to happen. I found a workaround in an app called PowerManager, which has a function that states "run script after ___ amount of inactivity, and it works and starts the screensaver even while connected to VNC! but it is $50 and I have to put it on multiple machines. I only need this one function, so I was hoping to write an applescript that basically does the following,

after 8min of inactivity run screensaver.app

and that script obviously has to be running continuously.

So yeah, any help would be much appreciated, I haven't done too much scripting but I can follow instructions.

Thank you!

Braven Carver



larkost
Apr 22, 2011, 11:31 PM
Can you be more specific about what you are doing, and why you need the screensaver to run?

bravencarver
Apr 25, 2011, 10:48 AM
Hello,

I need the screensaver to run even when connected to VNC, because the iPads will always be connected even when you re-dock them. I need the screensaver to run after inactivity to 1) show something appealing instead of the last window that was up and 2) to keep the image from burning in (some of the tv's we're doing this with are older plasmas)

Thanks,

Braven Carver

gnuguy
Apr 25, 2011, 11:16 PM
make sure you add the applicationServices framework then use


double idleTime;
idleTime = CGEventSourceSecondsSinceLastEventType(kCGEventSourceStateHIDSystemState, kCGAnyInputEventType);



This will give you the time in seconds that the system has been idle.

larkost
Apr 26, 2011, 11:41 PM
gnuguy, I had never seen the Carbon call for that, and had always worked my way thorough ioreg for it. Using Carbon is so much easier! And in case someone is looking for a script-ish way of doing it:

/usr/sbin/ioreg -c IOHIDSystem | /usr/bin/awk '/HIDIdleTime/ {print $NF/1000000000; exit}'