One touch shutdown
December 8, 2007 4:22 PM   Subscribe

Asking for Mr Waterlily: "I would like write a script that starts when the computer starts, goes into a permanent loop, looks to see if a key is pressed, if the key is pressed it would do something, if not it would pause n seconds then loop again. How does one detect key events in applescript?"

"I am running system 9.1. "

This is for a digital photo frame project made from an old powerbook 1400 we had lying around, if that's at all relevant. He wants it to automatically turn off the machine when a key is pressed (just shutting down instantly without bringing up any menus or options as the power button would). We are not mac people so if there's something easier he's missing, please advise.
posted by waterlily to Computers & Internet (5 answers total)
After a bit of googling around, this is the only hot key application for OS 9 I could find that's still available. The shareware version of KeyQuencer is (was?) $30 to register, but you might be able to get it for a steeper discount from the original designers if you write them a nice email explaining what you'd like to do.

If you're not doing this too frequently or you're not too worried about file corruption, holding down the power key on most Macs for an extended period of time will 'bypass' the system menu and directly shut down the machine.

Hope this helps.
posted by onalark at 7:42 PM on December 8, 2007

To me this sounded a little like "kiosk mode" so with the help of the google:
"In Mac OS 9 there is a utility called iDo Script Scheduler (and many others) that can run AppleScripts after a given idle time." The screenshot on the linked page shows a tantalizing amount of information - it can choose to ignore keystrokes, mouse movement, mouse clicks.

This is sort of the inverse of what you are looking for, but not knowing what you are trying to do, maybe you could reverse the logic in your script and this could work? Or maybe it will suggest another option?
posted by misterbrandt at 12:12 AM on December 9, 2007

Uh, on not-preview, you DO explain what you are trying to do. So not sure if my idea still works or not...
posted by misterbrandt at 12:13 AM on December 9, 2007

I made a kiosk slidehow appliance out of an old computer by installing Ubuntu 6.10 (Dapper Drake) on it and having it auto-logon to an account with the slideshow screensaver selected. It sat in the lobby of a primary school. No keyboard or mouse was connected at all. Staff would switch it on in the morning, and switch it off at night, just using the power button (Ubuntu just does a clean shutdown with no options asked for when you press the power button).
posted by flabdablet at 2:33 AM on December 9, 2007

If you wouldn't mind pressing two keys instead of one, when you press the power button it should bring up a dialog with Shut Down selected. Press enter and it will automatically shut down closing any open programs.

If you want to go further than that, check out Jon's Commands. It is an OSAX that adds more commands to AppleScript. It has a command called keys pressed.

I can't test this code directly, but if you install Jon's Commands, restart and save this as an applet with "Stay Open" selected and put it in your startup items, it should shut down when you hold down the option key for 1 second.
set Keypress_Counter to 0
repeat until Keypress_Counter = 1
if (keys pressed) contains "Option" then
set Keypress_Counter to Keypress_Counter + 0.5
delay 0.5
end if
end repeat
if Keypress_Counter = 1 then
ignoring application responses
tell application "Finder"
end tell
end ignoring
end if

posted by the biscuit man at 12:11 PM on December 9, 2007

« Older Please recommend informative documentaries or...   |   Info Junkie Seeks a Better Tool, One Site to Rule... Newer »
This thread is closed to new comments.