Skip to content

Instantly share code, notes, and snippets.

@mrienstra
Last active January 20, 2023 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrienstra/b7979c8b18f3403d742820a946ecbc8c to your computer and use it in GitHub Desktop.
Save mrienstra/b7979c8b18f3403d742820a946ecbc8c to your computer and use it in GitHub Desktop.

Batch import text substitutions

Based on https://nadnosliw.wordpress.com/unicode-characters/

Entering text substitutions is tedious, whether done using iOS, iPadOS, or macOS. Fortunately it's possible to import text substitutions using a .plist file, using the instructions provided here:

  1. Start with a text file mapping, here's one based on Dan Wilson's:
⁺ ^+
⁻ ^-
⁰ ^0
¹ ^1
² ^2
³ ^3
⁴ ^4
⁵ ^5
⁶ ^6
⁷ ^7
⁸ ^8
⁹ ^9
₀ ,0
₁ ,1
₂ ,2
₃ ,3
¼ 1/4
½ 1/2
¾ 3/4
⅓ 1/3
× #x
÷ #/
± +_
∞ #8
∝ #prop
√ sqrt
≠ !=
≈ #approx
⇒ =>
∴ ^…
∫ #int
➝ ->
← <-
↑ |^
↓ |v
↕︎ |^v
⇔ <->
✓ #v
✘ #X
⌘ #cmd
⏎ #ret
⌥ #option
⌃ #^
␛ #esc
α alpha
β beta
γ gamma
θ theta
λ lambda
μ mu
π pi
ρ rho
τ tau
σ sigma
δ delta
φ phi
ω omega
Ω Omega
Δ Delta
  1. You'll need to escape any occurrences of & or <. The example above uses < twice. Replace & with &amp; and < with &lt; as needed. One thing to watch out for: if you first change < to &lt;, and then replace all occurrences of & with &amp;, you can end up changing < to &lt; to &amp;lt;, which will result in a text substitution with &lt; in place of <.

  2. Next, using a text editor that supports regex -- I like VS Code -- use the following to convert to the required format:

Find:

^([^ \n]+) (.+)$

Replace:

	<dict>\n		<key>phrase</key>\n		<string>$1</string>\n		<key>shortcut</key>\n		<string>$2</string>\n	</dict>
  1. Finally, add this prefix:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>

And this suffix:

</array>
</plist>

The result will look a little something like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
	<dict>
		<key>phrase</key>
		<string>⁺</string>
		<key>shortcut</key>
		<string>^+</string>
	</dict>
	<dict>
		<key>phrase</key>
		<string>⁻</string>
		<key>shortcut</key>
		<string>^-</string>
	</dict>
</array>
  1. Save the file with a .plist extension (Apple uses Text Substitutions.plist as the filename when exporting).

  2. You may have XML errors, if you missed some occurrences of < or & in step 2. In VS Code, you can find those errors by looking for red in the scrollbar, then scrolling and finding the text with a red squiggly underline. Replace < with &lt; and & with &amp; as needed. If you're not comfortable editing XML, it's easier to go back to step 2 and replace those characters.

  3. Drag the file into System Preferences as described in the support.apple.com instructions above. You should see your new substitutions appear immediately. If they don't, something was wrong with your XML file. You can use an online XML validator if you're not sure how to proceed: https://www.google.com/search?q=validate+xml -- I tried https://codebeautify.org/xmlvalidator and it found the two errors.

The text substitutions should sync (fairly quickly in my experience) to other Apple devices via iCloud.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment