This question already has an answer here:

I've been looking into tools like Karabiner, which are cool, but I would like more control. In general, I'd like to remap specific keys to run AppleScript or some other code.

Ideally it wouldn't send the keystroke though to the active application.

Is there any way to do this?

At the moment I'd like to remap the numpad keys to focusing specific applications, and if possible, specific windows in those applications. A general way to run code would be best, but anything that can accomplish this would be very much appreciated.

marked as duplicate by Allan, Ɱark Ƭ, IconDaemon, Monomeeth Feb 28 '18 at 2:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • I believe Keyboard Maestro can do all of that. As with other similar programs that let you redefine keystrokes in order to trigger actions, it intercepts them before they get to the application originally intended to receive the keystrokes. You then decide what occurs from that point on. KM also has the ability to focus specific applications and, I believe, specific windows (referenced by index or title). – CJK Feb 27 '18 at 3:20
  • @CJK perfect! Please leave an answer so I can accept it. – Brigand Feb 27 '18 at 3:29
  • If you save your Applescripts in Automator as Services, you can call them by key command natively, no 3rd party apps required, though I've never checked whether they pass-through. I just avoid 'regular' key commands.. – Tetsujin Feb 27 '18 at 9:27
  • You can do this using Karabiner too... depending on your OS version. I made myself a launcher keyboard using a cheap bluetooth numpad and Karabiner (>>image<<). Though this was before Sierra using v.10.22.0. of Karabiner. That version of Karabiner supported detecting the active applicatio, triggering scripts and many other things. There was even an option to set alternative long press and double click (both of which I believe you can also do using Keyboard Maestro). – Joonas Feb 27 '18 at 11:52
  • I used to have a open files with photoshop button that opens selected files (in Finder or Path Finder) in photoshop and long pressing the same key just opened photoshop by itself. Karabiner had to be rebuilt to support sierra and so the Sierra version is lacking many of the features that were in the earlier version. The new version has been in the making for quite a while so I wonder how close it is right now. Just in case you are looking for alternative methods, there's the Elgato Stream Deck, which you can use for the same purpose. – Joonas Feb 27 '18 at 11:52

Browse other questions tagged .