Text substitutions for superscript and subscript There is a way to individually create text substitutions on Mac for most applications, by going to System Preferences→Keyboard→Text and then creating text substitutions. For example, I've made the following ones for ₂, ₃, × and ²³. 
If I wanted to, I could create more and more shortcuts like this, but that takes a lot of time. Is there a way to use Automator and/or Applescript and/or Terminal to make such substitutions for all such cases? For example, if I type _5002, it should come out looking like ₅₀₀₂.
Here is one solution using the command line:

Converting numbers to super/subscript

The sed utility allows you to use a translation table to convert characters to other characters:
$ echo &quot;abc513&quot; | sed -e 'y|0123456789|⁰¹²³⁴⁵⁶⁷⁸⁹|'
abc⁵¹³

$ echo &quot;abc513&quot; | sed -e 'y|0123456789|₀₁₂₃₄₅₆₇₈₉|'
abc₅₁₃

From there, we can write a tsubst script:
$ cat ./tsubst
#!/bin/bash

function superscript { echo &quot;$1&quot; | sed -e 'y|0123456789|⁰¹²³⁴⁵⁶⁷⁸⁹|'; }
function subscript   { echo &quot;$1&quot; | sed -e 'y|0123456789|₀₁₂₃₄₅₆₇₈₉|'; }

function phrase_from_shortcut_pattern {
  if [[ &quot;$1&quot; =~ ^\^(.+)$ ]]
  then
    # ^ -&gt; superscript
    echo &quot;$(superscript &quot;${BASH_REMATCH[1]}&quot;)&quot;
  elif [[ &quot;$1&quot; =~ ^_(.+)$ ]]
  then
    # _ -&gt; subscript
    echo &quot;$(subscript &quot;${BASH_REMATCH[1]}&quot;)&quot;
  else
    echo &quot;$1&quot;
  fi
}

phrase_from_shortcut_pattern &quot;${@}&quot;

That script takes one argument, a Text Replacement shortcut pattern with a ^ or _ prefix to indicate a super or subscript transformation, and returns the corresponding phrase:
$ ./tsubst _answer42
answer₄₂

$ ./tsubst ^answer42
answer⁴²


Generate phrases from lists or ranges of shortcut patterns

With that script, we can use bash loops and substitutions to generate phrases from a list of shortcut patterns:
$ for p in _42 ^42; do echo &quot;${p} -&gt; $(./tsubst &quot;${p}&quot;)&quot;; done
_42 -&gt; ₄₂
^42 -&gt; ⁴²

Or a range of shortcut patterns:
$ for p in _{6..8} ^{9..11}; do echo &quot;${p} -&gt; $(./tsubst &quot;${p}&quot;)&quot;; done
_6 -&gt; ₆
_7 -&gt; ₇
_8 -&gt; ₈
^9 -&gt; ⁹
^10 -&gt; ¹⁰
^11 -&gt; ¹¹


Adding text substitutions from the command line

This is the tricky part... I found one command-line utility that does its job well: shortcuts.
$ shortcuts read
0: &quot;jrv&quot; —&gt; &quot;J’arrive !&quot;
1: &quot;omw&quot; —&gt; &quot;On my way!&quot;

$ shortcuts create &quot;xyz&quot; &quot;XYZ&quot;

$ shortcuts read
0: &quot;xyz&quot; —&gt; &quot;XYZ&quot;
1: &quot;jrv&quot; —&gt; &quot;J’arrive !&quot;
2: &quot;omw&quot; —&gt; &quot;On my way!&quot;

$ shortcuts delete xyz

$ shortcuts read
0: &quot;jrv&quot; —&gt; &quot;J’arrive !&quot;
1: &quot;omw&quot; —&gt; &quot;On my way!&quot;


Automatically adding Text Replacement entries...

Now we can compose the two utilities to add entries to the Text Replacements preferences:
$ for p in _42 ^42 _{6..8} ^{9..11}; do
&gt;   ./shortcuts create &quot;${p}&quot; &quot;$(./tsubst &quot;${p}&quot;)&quot;
&gt; done

$ ./shortcuts read
0: &quot;^11&quot; —&gt; &quot;¹¹&quot;
1: &quot;^10&quot; —&gt; &quot;¹⁰&quot;
2: &quot;^9&quot; —&gt; &quot;⁹&quot;
3: &quot;_8&quot; —&gt; &quot;₈&quot;
4: &quot;_7&quot; —&gt; &quot;₇&quot;
5: &quot;_6&quot; —&gt; &quot;₆&quot;
6: &quot;^42&quot; —&gt; &quot;⁴²&quot;
7: &quot;_42&quot; —&gt; &quot;₄₂&quot;
8: &quot;jrv&quot; —&gt; &quot;J’arrive !&quot;
9: &quot;omw&quot; —&gt; &quot;On my way!&quot;

And the result in the Text Replacements preferences: