tags:

views:

284

answers:

2

How do I make an application that I can make the ESC key close a window? Or really any key (I can change if I want to).

Please help. Thanks

Here is what I have and I can't get it to work.

-- close window with "ESC"

tell application "System Events"
    tell application "Finder" to activate
    key code 53

end tell

beep 3

Thanks! B-

A: 

There's a system wide shortcut (Command + W) that will close the currently activated window

tell application "System Events"
    tell application "Finder" to activate
    keystroke "w" using command down
end tell

However, I'm not sure that this answers your question. Its impossible to use plain AppleScript to listen to system wide keyboard events. Take a look at the answer to this question.

macatomy
A: 

PCWiz's link should show you the way - have a look at the second answer (by ghoppe - setting keyboard shortcut to application in preferences). Just remember to save the script as application, otherwise it'll not be eligible.

sthat