25 April 2017

how to force-refresh macOS text auto-expansions without turning off iCloud

One of the little niceties OSX has had for a while is the automatic synchronization of text-expansion shortcuts across all iCloud-enabled Apple devices (i.e. what you find in System Preferences -> Keyboard -> Text on Mac, and General -> Keyboard -> Text Replacement on iOS). Unfortunately Apple tries a bit too hard to make it look "magic", which means that there is nothing one can do when the magic somehow refuses to work.

In my case, I ended up in a situation where the mac had lost all shortcuts. Various people on the internet recommend turning iCloud Drive on and off to get them back, but that's a very disruptive step I didn't want to take.

Luckily, this worked for me:

  1. Open a command terminal
  2. rm -rf ~/Library/Mobile\ Documents/com~apple~TextInput
  3. Log off
  4. make a change to the list of expansions on some other device (e.g. iPhone)
  5. log back on
This seems to have forced a refresh, and got all my shortcuts back.

It would be nice if Apple provided some command-line tool to perform this sort of explicit management for iCloud elements. As the saying goes, cache invalidation is one of the hardest problems in Computer Science; in order to do the right thing, any system needs all the help it can get. I should be able to say "just blow all my settings for this feature and refresh from iCloud" or "these are the good settings, overwrite whatever is in iCloud for this feature". Magic is nice, but as the citizens of Troy found out so many years ago, it's better to have backup plans for when the gods are against you.