Recent comments
Recent topics
|
Power down a headless mini?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.
More like this
|
Greetings,
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.
-Jason
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.
also http://developer.apple.com/mac/library/qa/qa2001/qa1134.html explains how to initiate a confirmationless shutdown.
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.
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!