Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have an old Macbook that I'm going to be tucking in a cabinet for use as a media server. It's currently running InsomniaX to keep it from sleeping when the lid is shut.

This works great when I start the Macbook with the lid open, wait for it to boot to the desktop (automatic login is enabled), then shut the lid. It stays running. This is good.

The problem is that when I start the laptop with the lid already closed, it boots to the desktop, but the lid detection puts the machine to sleep before InsomniaX has a chance to load. (Even though it's one of the Login Items for the account.)

Is there any way, be it hackish, technical, etc. to prevent the laptop from sleeping immediately? Even if it were to spin at the desktop for 30 seconds, it would give InsomniaX time to load.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Create a login hook that calls a script. Let's call this script noidle and put it somewhere, maybe ~/noidle.sh.

#!/bin/sh
pmset -a disablesleep 1

This script should run once and prevent sleep. To add this as a login hook, run:

chmod +x /Users/your-username/noidle.sh
sudo defaults write com.apple.loginwindow LoginHook /Users/your-username/noidle.sh
share|improve this answer
    
Haha unfortunately, the downside to this is that when it's run as a LoginHook, since the script never finishes, I can't actually boot into my account anymore. :) The login lifecycle seems to wait for this script to finish before continuing to the desktop, so now it just hangs at a blue screen. –  Craig Otis Jul 21 '12 at 18:24
    
Hmm. Can you try to pmset noidle &, that should put it into background and exit properly. –  slhck Jul 21 '12 at 18:35
    
Tried that, but it looks like when it's run in the background, it doesn't actually prevent the machine from sleeping. –  Craig Otis Jul 21 '12 at 18:49
    
Ah hah! I think I got it by changing the contents of noidle.sh to pmset -a disablesleep 1. (Since the login hook is run as root, the sudo can be left off.) Woo hoo! –  Craig Otis Jul 21 '12 at 18:54

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.