Macos – Wake a Mac display from sleep via SSH

macmacossleepterminal

I'm using Jenkins as a CI server, where I'm SSHing into an iMac running OS X Mountain Lion (10.8.4) to run some UIAutomation integrations tests on an iOS app. The iMac actually sits 10 ft from me (but across a table) so I'm able to see the screen. However, the tests don't wake up the display, so I often can't see them.

Is there a way to wake up the display from the terminal once Jenkins has SSHed in?

So far I have tried using Applescript to press an arrow key, and using the Wake Assist application. I also tried setting the wake schedule to be the current date. Finally, I tried using the caffeinate command: caffeinate -t 300 &. The computer's "Wake for Wi-Fi access" checkbox is enabled.

So far my best workaround is to just set the iMac to stay awake for atleast 3 hours. However, it'd be nice to keep normal sleep behavior, as I hypothesize that the screen waking from sleep would alert me visually that the integration tests are running. It's also significantly cooler 🙂

Best Answer

The Screen Saver is a standalone program which is started and stopped by the system according to the set triggers, such as time, or a hot corner, and appears in the process status list, but only if it's running.

I was able to stop the screensaver by:

killall -1 ScreenSaverEngine

It starts again when I trigger it with a hot corner, and by the normal timer, I just checked.

Related Question