20

I have a couple of custom shortcuts defined using System preferences > Keyboard > Shortcuts and I want to sync those between my two Macs.

It seems, this is still not possible using iCloud. Are there any other ways? I thought about including them into my dotfiles, but can not find the shortcuts using the defaults command.

P A N
  • 9,794
  • 20
  • 77
  • 114
nik
  • 311
  • 1
  • 6
  • 1
    I am adding a bounty to this question. Is there some alternative solution? Can the keyboard shortcuts be symlinked and synced through Dropbox? I guess the problem then would be that one Mac might have custom app keyboard shortcuts for an app that isn't installed on the other Mac...? – P A N Aug 21 '17 at 11:14
  • 4
    I can’t add this as an answer as it may be taken down. If you are having trouble with the Apple stuff, I’m not sure why but it works for me between macs and even iOS devices, have you considered moving to a third-party solution such as Keyboard Maestro, which can be setup to use Dropbox to sync between computers? https://wiki.keyboardmaestro.com/Syncing_Macros_Between_Macs – jasonology Aug 22 '17 at 01:33
  • 2
    @jasonology I can't see any reason why offering that as an answer would be a problem. In fact, I'd encourage you to do just that! :) – Monomeeth Aug 22 '17 at 04:02
  • 1
    @jasonology Can KeyboardMaestro bind custom shortcuts for previously non-shortcuted items in the applications' menu bar? I.e. as System Preferences > Keyboard > Shortcuts > App Shortcuts? That would be the holy grail for a third-party app to replicate the System Preferences options imo. I don't know that it's possible with BetterTouchTool (maybe it is?). – P A N Aug 25 '17 at 16:43
  • 1
    @jasonology, thank you for the suggestion. I pulled the trigger on buying Keyb. Maestro and it's doing exactly what I want, including DB sync. I wonder why your answer is removed, as it's best for me. Winterflags, I migrated my SysPref ones to Maestro one by one, it's not that hard, and worth it. – SilverSideDown Sep 20 '17 at 14:01
  • Update from 2020: when you open System Preferences -> Apple ID -> iCloud Drive (on the right pane) you can see System preferences.app. I searched alot about that and enden up talking with apple's support. They told me that this setting allows to sync Universal Access settings and things like the fact that terms of use were accepted (shown when accessing first time to some apple's apps). I asked about hotkeys settings in Keyboard menu - they told me that it is not synced. – Arkemlar May 09 '20 at 14:06

2 Answers2

9

Since you're using dot files, if you know what shortcuts you want to create ahead of time, you can add them to all machines by adding the following defaults write commands to your setup script:

Per App Shortcuts: defaults write com.developer.app NSUserKeyEquivalents -dict-add "Menu Item" -string "keyboardShortcut"

Global Shortcuts: defaults write -g NSUserKeyEquivalents -dict-add "Menu Item" -string "keyboardShortcut"

...where com.developer.app is the application's bundle ID, and keyboardShortcut is the letters of the keys you want to include, plus the symbols @, $, ~, and ^ representing the Command, Shift, Alt, and Control keys, respectively. For example, -string "@~K" would represent the keyboard shortcut K.


If you need to sync existing shortcuts, you're going to have to make a more complicated script. I imagine this would involve reading or comparing shortcuts on a source machine via:

Per App Shortcuts: defaults read com.developer.app NSUserKeyEquivalents

Global Shortcuts: defaults read -g NSUserKeyEquivalents

...and writing them to a target machine via:

Per App Shortcuts: defaults write com.developer.app NSUserKeyEquivalents 'outputOfSourceMachine'

Global Shortcuts: defaults write -g NSUserKeyEquivalents 'outputOfSourceMachine'

Wowfunhappy
  • 7,383
0

Adding onto @Wowfunhappy's answer: I wrote the following bash function to auto-generate defaults write shortcut-setting commands from existing application shortcuts (e.g. app-shortcuts Finder). It shows global shortcuts when no arguments are passed or the empty string is passed (app-shortcuts or app-shortcuts ''). Accepts arbitrarily many inputs.

appid() {
  local app
  for app in "$@"; do
    osascript -e 'id of app "'"$app"'"' \
      && mdls /Applications/"$app".app | grep kMDItemCF
  done
}

app-shortcuts() { local key app apps appid appdata key=NSUserKeyEquivalents [ $# -eq 0 ] && apps=('') || apps=("$@") for app in "${apps[@]}"; do [ -z "$app" ] && echo "# Global shortcuts" || echo "# Application: $app" [ -z "$app" ] && appid=-g || appid=$(appid "${app}.app") defaults read "$appid" "$key"
| tr -s ' ' | sed '1d;s/^/-dict-add/;s/ = / -string /;s/$/\$/;s/;$//;$d'
| while read -r appdata; do echo "defaults write $appid"$' \\n '$"$key $appdata" done done }

I have two macbooks and keep them mostly synced with Mackup, but mackup cannot sync shortcuts, so I use this function to generate lines for a shortcut-syncing bash script.