10

Some apps (e.g. Tweetbot) have single-key keyboard shortcuts.

However, when trying to set shortcuts in System Preferences, we’re not allowed to do the same. Is there a user-facing way of achieving this?

3 Answers 3

10

It is possible to do, both natively and easily. Mac OS X hints has a hint (also check Lri’s comment) on how to set up keyboard shortcuts from the command line. We can use this to create single-key shortcuts.

You’ll need to know the application’s bundle ID (unless you want to set global shortcuts, naturally). For special keys, @ is ; ~ is ; $ is ; ^ is ctrl. You can also check other values.

I’ll use Tweetbot as an example, setting “New Tweet” to +N, and “Reply” (on the multi-shortcut example) to R.

For one-shortcut commands, you can use the form:

defaults write com.tapbots.TweetbotMac NSUserKeyEquivalents -dict-add "New Tweet" -string "~n"

For multi-shortcut commands, use the form:

defaults write com.tapbots.TweetbotMac NSUserKeyEquivalents '{
  "New Tweet"="~n";
  "Reply"="r";
}'

For system-wide shortcuts, use -g, instead of a bundle ID.

2
  • 1
    After setting the defaults via the Terminal, if I make any keyboard shortcut changes via System Preferences, it seems to delete my custom defaults entry. :(
    – nicjohnson
    Commented Oct 28, 2016 at 16:37
  • For nested menu items, use \etitle1\etitle2\etitle3
    – hym3242
    Commented Jun 15 at 9:27
0

I doubt that you can have a system wide single key shortcut to do something like a cut and paste for instance, if that's what you're asking. Doing so would cause the actions to be triggered when you're typing an email, for example.

Some apps allow that most probably because they're programmed so that the single key shortcuts are only detected in certain modes/interfaces. But I could be wrong about Tweetbot because I've never used it :)

2
  • I doubt it too, and I certainly understand the implications; I’m in no way suggesting a system-wide shortcut. OS X lets you set shortcuts on a per-app basis. Detecting whether said app is in “input text mode” or not could very likely be detected.
    – user137369
    Commented Jun 9, 2014 at 21:59
  • Gotcha. I guess it would be useful in your situation if OSX detected if an keypress event is being handled by the app before the user defined keyboard shortcut takes control. But nope...don't see a way in doing that.
    – user81261
    Commented Jun 10, 2014 at 5:40
0

This is likely too late to help in future, as it's broken in Ventura. Prior to Ventura you can generate a single-key shortcut by pressing Fn [character] in the Shortcuts pref pane.

For example, adding just an H as shortcut to Safari Help by actually pressing Fn h in the entry box.

enter image description here

This produces

enter image description here

in the menu itself & works from a single key-press.

Fortunately for this kind of structure, if you're typing in a text area the shortcut is not triggered.

2
  • bummer this doesnt work anymore
    – mihai
    Commented Jul 25, 2023 at 18:09
  • As advised in my opening sentence.
    – Tetsujin
    Commented Jul 25, 2023 at 18:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .