another newbie question - key down command the eject button

i’m fairly new to programming in applescript. Though not too new.

Here is what i'm trying to do:

Script out a set of keystrokes to pull up the dialog box offering the restart, sleep, cancel, and shutdown options. the physical action is to press control + the eject key.
So far this is what i have, any help or answers would be great.

it’s generally good to stay away from GUI scripting when possible. there are a few different ways to do this with custom dialogs. here’s two options that i could think of. i like the second one best because you could add as many choices as you want. hope this helps.


set theChoose to display dialog "What to do?" buttons {"Cancel", "Restart", "Shut Down"}

if theChoose is equal to "Restart" then
	tell application "System Events"
		restart
	end tell
else
	tell application "System Events"
		shut down
	end tell
end if

or


set theList to {"Sleep", "Restart", "Shut Down"}
set theChoice to choose from list theList
set theResult to theChoice as Unicode text

if theResult is equal to "Sleep" then
	tell application "System Events"
	sleep	
end tell
else if theResult is equal to "Restart" then
	tell application "System Events"
		restart
	end tell
else if theResult is equal to "Shut Down" then
	tell application "System Events"
		shut down
	end tell
end if

be careful when saving the first one from ScriptEditor because you could end up running the script and turning off your machine. like i said, the second one is probably best for what you need to do.

i appreciate the help on that, i already wrote a script similar to the two you’ve posted. and while it works, it’s the challange of trying to script that specific action. i guess i’ll use what i’ve got for now. at least till i can find what the modifier name of the eject key.

oh i thought it was a functional script, not a practice one. sorry i can’t help you with the GUI thing.

Hi,

I think the dialog you’re referring to is an event of the loginwindow app. I think it was never fully connected with a possible future System Events command ‘log out’. So, it’s just sitting there and you can’t Control + F12 because this causes an interrupt. I’m just guessing but you should perhaps use the ‘choose from list’ or create your own dialog.

Somewhere in the back of mind I’m thinking that I might have gotten that dialog to open through AppleScript, but not sure.

gl,