Unable to run scheduled AppleScript/Automator after screen sleeps

Environment:
I’m scheduling AppleScripts using Automator on Mac OS X 10.9.4. I’m scheduling it with Calendar. I’ve tested the scripts on a MBP 17" Early-2010 and a MBP 17" Mid-2011

The Issue:
The scripts will not run when the screen sleeps or after the system has just been scheduled to “wake up.” If the screen is unlocked and awake or the screensaver is on and the screen is awake, the scripts will run fine.

My theory is that the primary issue has to do with No capable display being found.

A screenshot of my log in the Console when the AppleScript was scheduled to run can be found here.
https://drive.google.com/file/d/0B0jD59pT37M-ZXU4NldnRG5ISFE/edit?usp=sharing

Desired Outcome:
Ideally, we’d like to keep the screen off and not even have to login to the machine to run the scheduled scripts, but that doesn’t seem to be an option right now.

Current Workaround:
We are keeping a Mac on all the time with at least the screensaver on with a screen lock at the lowest brightness setting. At the top of my script, it detects whether there is a screensaver running and then unlocks the login screen if there is one.

Attempts to fix the issue

I’ve tried a variety of different things to try to simply activate the sleeping screen when it’s a asleep without human input. Though it would be ideal if the script would run with a screen that’s off, simply getting the screen to wake up and logging in would be great too.

I used this post specifically from this forum as well as other techniques: http://macscripter.net/viewtopic.php?id=41950

Caffeinate:

delay 4
do shell script "caffeinate -u true"

Using shell app called cliclick to use terminal to make a click:

do shell script "'/usr/local/bin/cliclick' c:."

Using freeware Caffeine

tell application "Caffeine"
      turn on for 10
      delay 10
      quit
end tell

Any help would be appreciated.

Hi goemeister,

What you can do is schedule the computer to wake at a certain time and run a script. I think you can also have a script run at a certain time even though the computer is sleeping, but I need to check out that.

Edited: yes, I don’t think you can have a script run when the computer is sleeping.

gl,
kel

Try looking in this post:
http://macscripter.net/viewtopic.php?id=40294
I haven’t looked back through it yet.

gl,
kel

McUsr mentioned ‘launchd’ in the last post of the link. I think that is what you need.

gl,
kel

Hi,

One thing I was thinking about was that I think Apple deprecated crontabs. So, you need to watch out what apps you use.

gl,
kel

Hi kel,

Thanks for your quick response. What I’m looking for specifically is running a script when the screen is asleep or finding a way to wake it up so the AppleScripts will run. I can use the scheduled feature built into the OS to get the machine to come out of sleep. The problem is the monitor will remain off and thus no scripts will run.

So in summary, if the screen is asleep or powered down (though not the computer), the AppleScript will not run. I have found no script thus far that will help the screen become awake without physical interaction or logging in through screenshare / VNC.

Thanks.

Hi geomeister,

You could use pmset to wake the computer and do other things with power. See the man page. For example:

You could add this to your script. I can’t remember if it needed a password.

gl,
kel

Hi geomeister,

I had to do some review. Here’s an example of how you might schedule wake:

do shell script "sudo pmset schedule wake \"07/04/14 07:00:00\"" password "mypassword" with administrator privileges

Storing and retrieving the password on your computer is another story.

Hope it works with your display theory.

gl,
kel