Scripting Screensaver

Discussion in 'Mac Programming' started by bravencarver, Apr 22, 2011.

  1. macrumors newbie

    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

    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
  2. macrumors 6502a

    Can you be more specific about what you are doing, and why you need the screensaver to run?
  3. macrumors newbie

    Scripting Screensaver


    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)


    Braven Carver
  4. macrumors newbie

    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.
  5. macrumors 6502a

    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}'

Share This Page