Power down a headless mini?

sbn..'s picture

Hey again.

As discussed in this topic, i'm doing an installation involving some hardware sensors and a Mac Mini.

I've gotten quite far, and everything looks good - except I want the computer to be able to be powered down in the normal manner (no force power off / hold power button). The people running the gallery need to be able to reboot if there's any trouble, and shut down for the night. A keyboard won't fit in the installation.

Is there any good way to bypass what Apple calls the "power key window", the one that comes up when the power button is pressed? The one that offers the option to "Restart, Sleep, Cancel, Shut Down"? Ideally, one press of the power button should initiate a normal shutdown directly.

I've looked at UIMode from Carbon, but that simply has the ability to make the power button non-functional. I'm doing a fullscreen app from a modified Apple sample and am not afraid to get my hands dirty with some Obj-C. I'm also not afraid of reading documentation, but can find nothing further on this.

The simple way would be to hand the installation guys a keyboard, and tell them to plug it in before powering down. But that just seems inelegant when all that's needed is one press of the enter key.

Thoughts and anecdotes are, as always, appreciated.

jmlnorris's picture
Re: Power down a headless mini?


Using a VNC client from another computer or iPhone would let you easily exit the program you're running and click on the "shutdown" option in the Apple menu. Not graceful, but possible. Another option might be use the "Command Line Patch" to trigger an Applescript from inside your Quartz comp. If you're already wiring sensors into the mac mini, then what's one more that just triggers a "shut down" script? I looked at making an Automator workflow that would "quit all apps" and then "shutdown" the computer, but it appears that Automator can only restart the machine, not shutdown it. I hope this gives you some ideas.


smokris's picture
Re: Power down a headless mini?

also http://developer.apple.com/mac/library/qa/qa2001/qa1134.html explains how to initiate a confirmationless shutdown.

sbn..'s picture
Re: Power down a headless mini?

Thanks for the suggestions. The trouble is that the sensor hardware is built and tested, plus cased in a nice box. I could add a switch if really needed, but honestly I think it's weird that there's no prefpane for this. I mean, the power button is right there and used to turn the thing on anyway.

The good news is that I've hacked it. Not elegantly, but it works. I ended up coding a small QC plugin that generates a low-level return key press. Then, I connected that to an LFO inside the composition so it triggers once every ten seconds. Using Kineme's fullscreen method in stead of Apple's (that's outdated as far as I can tell), the "power key window" will appear on top of the fullscreen composition when the power button is pressed. Then, inside ten seconds, that window will receive a return key event, activating the default "shut down" button.

This only works because I don't use the return key for anything else, and because the QCView silently consumes the events in normal operation.

Whew! What an ugly workaround.

Edit: I should add that we'll build the Mini + sensor hardware (Arduino) + scan converter (it's an analog monitor w. composite in, which the new Minis can't do) into some wooden box or otherwise out of sight. The power button will therefore be out of reach, but having a normal keyboard there as well would make it very much harder to conceal. Power in and signal out will be the only visible cables.

sbn..'s picture
Re: Power down a headless mini?

Thanks for the tip.

If I could intercept the power button press as well, I could hook those up. Would be cleaner.

sbn..'s picture
Re: Power down a headless mini?

Argh... Assumptions are dangerous.

Turns out that the mini behaves differently than the macbooks. No "power key window " appears when you press the button - you have the choice of the power button putting the computer to sleep, or it doing nothing at all.

That means I've had to ditch the method described above, BUT: Thanks to your tip, I was able to put the IOKit power down method inside a sleep notification callback. When the power button is pressed, it sleeps the computer. This triggers a "computer will sleep" notification to my app - inside the callback, the app then shuts down the computer.

Woo, thanks again!

stephanschulz's picture
Re: Power down a headless mini?

Hi Simon.

Do you think you can post your working code. I am having trouble delaying the sleep event, to give the shutdown code enough time to be executed.

thanks, stephan.

639me's picture
Re: Power down a headless mini?

in sys.prefs, energy saving you can set times for turning on and off. also you could make two applications in automator, one that shuts your qc down, and one that opens your qc file and goes fullscreen. make alarms in ical that triggers these

robbietherobot's picture
Re: Power down a headless mini?

Can you use Remote Apple Events? IE a AppleScript over the network (WiFi)?

IE AppleScript

set remMachine to "eppc://username:password@"
using terms from application "Finder"
   tell application "Finder" of machine remMachine
   end tell
end using terms from

We use "iPhoneRemote" on an iPod Touch with lots of these remote scripts to control our exhibitions. (http://code.google.com/p/telekinesis/)

Or use a Bluetooth keyboard to trigger the AppleScript?

psonice's picture
Re: Power down a headless mini?

it's fairly trivial from the command line. Enable remote login on the mini, from the desktop you just ssh in and do "sudo shutdown -r now". It's fairly easily made into a shell script, which can then be run from and icon with a single click.

sbn..'s picture
Re: Power down a headless mini?


I'd completely overlooked that this topic was active again, sorry.

Yes, I'd be happy to. It's a modification of Chris Wright's QCFullScreen app available at this site, with some Apple example code pretty much just cut'n'pasted in there.

In other words, it's messy, and I'm not sure how strictly to read Chris' "All rights reserved" note in the file I've modified. I'll happily spend a little time cleaning it up and such, but does anyone have tips regarding how best to do it? Should I post code snippets only, modify the original and note this in the comments, or what? Of course I want to respect Chris' work and wishes.

smokris's picture
Re: Power down a headless mini?

sbn.. wrote:
I'm not sure how strictly to read Chris' "All rights reserved" note in the file I've modified.

That code is covered under the MIT license. You're free to reuse and redistribute it according to those terms. I just added a note to the Simple Fullscreen QC App page, explaining that.

sbn..'s picture
Re: Power down a headless mini?

Thanks for the clarification, smokris, and for the work you and cwright have put into establishing such a relatively small but immensely helpful community here. I don't know where I'd be without this resource.

Probably using Isadora or Jitter or something ;)

In any case, here's the modified QCFullscreen app. There are a few caveats though; mostly because I handed the Mini over after producing the installation, so I can't test right now that it absolutely works. My rigorous data hygiene (no joke) tells me that this version is the one that shipped.

It will build, but without the composition (which I think I renamed from 'myCompo.qtz'), you might be stuck with a black screen. The force quit window wouldn't even show unless I cmd+tabbed to another app, then hit cmp+opt+H to hide others.

Look in appController.m to change the path back, or use it the way I did: with a file called "main.qtz" placed along side the built application.

All right, that out of the way, the code I've added is from docs plus at least two separate Apple examples. I'm pretty messy that way, I stop when it works and don't generally clean things up (I can spot a few lines that are probably redundant). It was also necessary to add some complexity to have the mouse hide properly.

I used this application with nothing but power and video and audio out connected. No mouse or keyboard. Then I'd add the QCFullscreen application to startup items, and make sure that the power button was set up to put the machine directly to sleep. That way, the gallery could run the installation by pressing the power button once in the morning, and once at closing time. It would then have a nice clean shutdown, and in case of problems the first fix would be to cycle it off and on.

Hope this helps!

QCFullscreenKiosk.zip67.28 KB