Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

This is a two part question. A practical, "how to" question is first, and then I ask for configuration suggestions.

First, I put my displays to sleep at night, and I would like to be able to wake the display remotely. Is there a command line utility I can use to wake it via SSH? I know about WakeOnLan, but that seems like overkill.

Second, the whole reason for me wanting to wake my display remotely has to do with how Lion's power savings settings changed. The Apple infrared remote no longer wakes the display. This is a huge deal for a machine I originally bought to be a combined desktop/home theater pc, since it defeats half of its purpose. So, does anybody have any ideas/suggestions what to do about this? This is open ended, I know.

share|improve this question

4 Answers 4

You can use

pmset schedule wake "01/01/2012 20:00:00"

to wake up a sleeping display on an otherwise "awake" Mac. Replace the date/time part with current time of course.

share|improve this answer

Waking the Display from the Command Line

For waking your display remotely, try running an AppleScript on the command line:

osascript -e 'tell application "System Events" to key code 123'

This will simulate pressing the cursor key and should make Mac OS X 10 believe a user is active on the computer.

This AppleScript is based on the answer, How do I automate a key press in AppleScript?

Waking the Display after Waking with the Remote

If you are waking your Mac using the remote and the display is not powering on, try Wake Assist. It is not designed for this situation but might just work.

Wake Assist simulates a mouse click after your Mac wakes up. The mouse is clicked twice in the upper-left of your main display. Wake Assist will do nothing if it detects a user but if the computer wakes and is idle, then the mouse is clicked for you.

share|improve this answer
1  
The AppleScript thing did not work for me. I get a black image from screencapture even after waiting a few minutes. –  lhf Jul 18 '12 at 18:02
    
Have you tried any other simulated key presses - maybe the cursor key is not enough? Do you require a password on wake? –  Graham Miln Jul 19 '12 at 9:34
1  
Worked fine for me on OS X 10.6 –  claytron Nov 14 '12 at 23:15

Oh, how I wish I had enough rep to upvote @wuc's answer the 10 times it deserves for this maddeningly frustrating problem (or to at least be able to leave a simple comment with the praise it deserves).

Apple, in its paternalistic wisdom, added a "feature" that intentionally made it harder to wake the display on Lion and Mountain Lion. This has made life much harder for those desiring to remotely wake the display (using IR remotes or via VNC) to interact with their Macs . For some reason, this became more pronounced with OS X 10.8.2.

Using pmset was a marvelous workaround for me.

Step 1: Login to the remote machine using ssh myname@192.168.1.2 (replace with an appropriate username and ip for the remote Mac).

Step 2: Wake up the display using pmset schedule wake "06/27/2013 04:20:00" (with an appropriate future date of your choosing).

share|improve this answer

wuc wrote:

You can use

pmset schedule wake "01/01/2012 20:00:00"

to wake up a sleeping display on an otherwise "awake" Mac. Replace the date/time part with current time of course.

However, that didn't work for me on a circa 2008 iMac running 10.9.1 or a late 2010 MacBook Air running 10.9.2. I'm not sure if this has something to do with Mavericks' energy management or the hardware, or what.

I was able to get it to work by setting the wake time to be 15 seconds into the future. Occasionally I was able to get it to work with the setting as low as 12 or 13, but not reliably. But there may have been other factors I didn't realize at the time, but 15 worked, so I used 15.

But how do you calculate 15 seconds into the future programmatically?

I used gdate from the GNU Coreutils package (date in OS X might be able to do this, but if it can, I don't know how, and I already had gdate installed):

[to use date instead of gdate use alias set_wake_time='date "-v+${OFFSET}S" "+%D %T"']

Here's the script I used:

#!/bin/zsh -f

# how many seconds into the future we want to wake the display
# 15 seems to work reliably. YMMV.
OFFSET=15

# to calculate the time, we need `gdate`
alias set_wake_time='/usr/local/bin/gdate --date "+${OFFSET} sec" "+%m/%d/%g %H:%M:%S"'

# this is where we set the wake command
# if it doesn't succeed the script will exit immediately
/usr/bin/sudo /usr/bin/pmset schedule wake "`set_wake_time`" || exit 1

# if you were not testing this, you'd probably want to end at the
# next line. Just remove the leading '#'
#exit 0
#######################################################

### Everything below this line is only needed during testing ###

# this tells the display to sleep
# because we can test waking the screen up unless it's asleep
pmset displaysleepnow

# for testing purposes: now the script will pause for $OFFSET seconds
sleep $OFFSET

# For testing purposes:
# after $OFFSET seconds, this sound will play 3 times.
# by that time, the display should be awake
# I did this to help me know when I had set OFFSET too low

afplay /System/Library/Sounds/Glass.aiff

afplay /System/Library/Sounds/Glass.aiff

afplay /System/Library/Sounds/Glass.aiff

# script is done
exit 0

Everything after the '#######################################################' can be removed once you have finished testing.

share|improve this answer
    
date -jv+15S will do the trick of calculating the date 15 seconds in the future from now. The -j switch prevents date from trying to set the system clock. –  mike Apr 4 at 15:29
    
Oh, hey, thanks! –  TJ Luoma Apr 7 at 14:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.