2
  1. In System Settings -> Keyboard -> Keyboard Shortcuts -> App Shortcuts it is possible to define application-specific shortcuts for menu entries.
  2. My main problem is that I have quite a long list of shortcuts and it is quite cumbersome to type them into Mac's settings UI individually when setting them up again on a new machine
  3. It is cumbersome because the strings have to be exact + after each entry, I have to stop and press the shortcut key itself

Is there a way to write a script and perform this, or to transfer them to a new machine by other means?

0

2 Answers 2

1

You can create a shell script that will set a series of key shortcuts for menu items.

The format uses @ for Command; $ for Shift, ^ for ctrl, ~ is Opt/alt.

The usual format for the commands would be:

defaults write com.google.Chrome NSUserKeyEquivalents -dict-add "Bookmark This Tab..." -string "@b"

... for each command.

The menu command must be spelled correctly. Apple has changed its mind about whether the ... is one ellipsis character or three periods.

You can also specify submenu commands using:

"\033Menu\033Sub-item"

A script with a sequence of commands can be assembled in a text editor, with the appropriate first line, specifying the shell.

0

I ran this command defaults read com.google.Chrome which yielded the JSON-looking output containing my shortcut keys.

% defaults read com.google.Chrome         
{
    LastRunAppBundlePath = "/Applications/Google Chrome.app";
    NSUserKeyEquivalents =     {
        "Bookmark This Tab..." = "@b";
        "Open Location..." = "@d";
        "Reload This Page" = "\\Uf708";
    };
}

So to write

% defaults write com.google.Chrome NSUserKeyEquivalents '{
    "Bookmark This Tab..." = "@b";
    "Open Location..." = "@d";
    "Reload This Page" = "\\Uf708";
}'
2
  • Have you tried it? I'm not convinced the syntax is correct.
    – benwiggy
    Jul 11, 2023 at 16:24
  • Which part of the syntax is wrong?
    – bilogic
    Jul 11, 2023 at 16:26

You must log in to answer this question.

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