MacOS – How to script a global keyboard shortcut in MacOS

command linekeyboardmacosscript

I want to configure a global keyboard shortcut in MacOS using a script.

Specifically, I want to set the "Move focus to next window" to ⌘⇧§ (since I have a Swedish keyboard and the default ⌘⇧` has a tendency to insert backquotes all over the place)

So I want the setting to end up like this Keyboard shortcuts with "Move focus to next window" focused

I have tried this command

defaults write -g NSUserKeyEquivalents '{ "Move focus to next window"="@§"; }'

Inspired by this and this instruction. But it does not work.

Best Answer

Well, if you want to set the "Move focus to next window" to ⌘ ⇧ § you'll obviously also need two modifiers along with the § key. (Your screenshot is contradictory to this, though.)

Your script has to contain an additional "$" here: '{"Move focus to next window"="@$§";}'.
Maybe this will work?