I was wondering if it was possible to run an applescript when a keystroke is pressed without the use of a third-party app. An example of this is Alfred, a free app on the app store. With a keystroke (such as Command-A), it will open.
Yes, my application will have ‘Application is Agent’ in the plist file, and it will be my daemon that responds to the events. My question is what code do I write to have it respond to the keystroke?
Okay, did some of my own research, and this is what I learned.
script AppDelegate
property parent : class "NSObject"
on hotKeyDetected_(aNotification)
log aNotification's userInfo()
end hotKeyDetected_
on applicationWillFinishLaunching_(aNotification)
current application's NSEvent's registerHotKeys_notificationName_({{keyName:"hotKey1", keyCode:44, modifier:786432}, {keyName:"hotKey2", keyCode:47, modifier:786432}}, "RDKeyDownNotification")
set Noter to current application's NSNotificationCenter's defaultCenter()
Noter's addObserver_selector_name_object_(me, "hotKeyDetected:", "RDKeyDownNotification", missing value)
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
end script
So what I want to figure out is how to know what key code it is. So an example would be that the user would choose the key code and then it would work with that key code.
Uhg… This is a hard problem, and I seem to be stuck. All I need to do is have my application run a shell script when a certain key code is pressed. When I try the methods in the thread you sent me, I am constantly getting errors, such as : Undefined symbols for architecture x86_64:
“_main”, referenced from:
start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
If it isn’t annoying, could you please send me what I am suppose to do since I can’t seem to figure it out on my own…