Search code examples
macoskeyboard-shortcutskey-bindings

how to programatically reassign keys in OSX?


Is there an easy way to remap one keystroke to another in OSX El Capitan?

I want to assign F13 to ⇧⌥⌘4. (I use a little app called Imgup and that's the keystroke to upload a screenshot.)

This answer suggests using Keyboard Maestro. But I'm already running Karabiner and USB Overdrive so I'm hesitant to install more software.

I'm looking through the options in Karabiner and I don't see how to simply remap one key press to another, and obviously "upload screenshot to Imgur" isn't one of the choices since it's not a system command. Also I can't use "App Shortcuts" since in Imgup there's no menu item for this action.

Is there a simple format for writing an XML snippet in Karabiner that would allow this? Something like this?

<item>
<name>F13 to ⇧⌥⌘4</name>
<key><f13>
<definition>4 with Command AND Option and Shift down</definition>
</item>

Solution

  • Sorry I'm late to the party, but here's how to do it:

    1. Open Automator
    2. Create a new document of the type Service
    3. At the top of the right pane, change "Service receives selected [ text ]" to "Service receives [ no input ]" in [ any application ]
    4. In the left pane, locate Run AppleScript and drag it over to the empty area in the right pane
    5. Delete everything already in the AppleScript box, then copy and paste this in:

      on run {input, parameters}
      
          tell application "System Events"
              key code 21 using {command down, option down, shift down}
          end tell
      
          return input
      end run
      
    6. Run the Service using the Play button in the top right of the window to make sure it does what you want.

    7. Save the Service using whatever title you'd like. This will make it available system-wide.

      Now it's shortcut time.

    8. Open System Preferences > Keyboard > Shortcuts, and select Services in the left pane

    9. Scroll down to the bottom to find your newly-created Service entry and add a shortcut by selecting the word none to the right of it. In your case, this is where you'd press the F13 key on your keyboard.
    10. Switch focus to any other app (Finder, for example) and give the new shortcut a shot.
    11. Profit