In part 1 I ended with the idea of using this in to some AppleScript routines but hit a number of design issues with the syntax:
- Writing everything as a single list is not ideal for scalable or re-useable code.
- The syntax doesn’t really lend itself to scripting routines
- The big list was a LOT of escaped text and a pain to edit
- The main problem – the methodology if run again (say for another project) would replace any existing shortcuts, rather than appending. Less than ideal for building or adding to a set of shortcuts.
Fortunately I recently found a second approach which solved all of the above.
This changes the syntax a bit, but most of the existing work can be reused (for the specific menu drill down using \033) and the shortcut notations (like \UF70D for F10)
To break down the improved syntax:
- The command and domain remains (defaults write com.captureone.captureone13 NSUserKeyEquivalents)
- This is followed by the specifier for add new key/value pairs to the dictionary (-dict-add)
- Then this is followed by the value pairs of menu title and shortcut (in quotes, separated with space)
e.g. “\\033Scripts\\033My Folder Name\\033My Script” “\\UF70D”
A full command (including escaping) now reads:
defaults write com.captureone.captureone13 NSUserKeyEquivalents -dict-add "\033Scripts\033My Folder Name\033My Script" "\\UF70D"
This new approach means you can chop up this command line in a “do shell script” with some injected variables, and each and every invocation will add the shortcut to the dictionary.
Still a bit to do for the working script but will try to make that the next post!