How to create a macro to expose expanded characters

Hi, I'm new to KM, and to Mac. I've searched a bit, but I can't find exactly what I'm looking for, and I am finding KM a bit overwhelming.

I use primarily one program for professional work that does not utiilize OpenType. On PC, I used AutoHotKey to create a script I called "Typography Boost." When I press a key (in that case, F12), it turned on the script, gave me a little popup saying "Substitution on," and changed the mapping of the keyboard to something like:

a = á (press-and-hold does not work in this program, and it's slower).
A = small-caps A

as well as

1 = superscript 1
Shift-1 = oldstyle 1

I mapped these according to their Unicode points. Then pressing F12 again would turn it off.

I would like to do the same on KM. It looks like a very powerful software (and I was amazed by the scripts posted on the forum). I'm wondering if it could also allow different variations of these mappings, since there are sometimes different Unicode points depending on the typeface I'm using.

I'm very willing to learn how to do this myself, I just need some starting direction. Thank in advance!

Take a look at my Text Toolbox:

It has an option to enter Diacritics (recently updated here) and another for special characters via popup menus. They should illustrate how to do it.

1 Like

Thanks for sharing that macro, much appreciated. But it's not quite what I'm looking for, unless I'm not understanding how it works. I only want to press F12, type a capital letter to return for me the small cap of that letter (as one example), and press F12 again to end the macro. There about 40 or so substitutions that I want to be able to access. I want to do it without using the mouse, or needing to look at the screen... just F12-keystroke-F12, as I've been used to that for years now.

Again, I'm new to KM, so I may have misunderstood how your macro works. I am actively working through the documentation, so I'm trying to learn as I go. Thanks.

In order to make this work the way you want it to work, Keyboard Maestro would have to trap every character you type, basically making it a key logger. That functionality doesn't exist in Keyboard Maestro, at least not that I'm aware.

You could possibly do something like pair a Keyboard Maestro macro with a TextExpander set, where the macro key activates a TextExpander replacement set, and then when activated again, disables it. NOTE: I don't use TextExpander any more, so I don't know if that's even possible ... but I seem to recall it offers the ability to have sets of replacements, so maybe.

If you want a fully Keyboard Maestro-only solution, I can think of two ways to do it, neither of which would be as fluid as your prior solution. One way would be to type what you want to type, then select the text and execute a macro. The macro could then copy the selection, and read each character, replacing each as necessary based on definitions in the macro.

The other would be similar to your method, but much uglier. When you press F12, an input box appears onscreen. You type your capital letter (or whatever), and then the macro inserts the corresponding replacement character. This would work, but would be really visually disruptive. The box then reappears each time, until you press F12 again. Ugly and not close to ideal.

In short, I can't think of a way to do what you want in Keyboard Maestro; perhaps someone else can. I personally think you'd have better luck with something like TextExpander or Typinator or similar, as those apps are key loggers, and trap and evaluate every character you type.


Can you share the script for examination?

Sure, thanks. Here it is:

	Sub := !Sub
	ToolTip, % "Substitution " . (Sub ? "ON" : "OFF")
	SetTimer, ToolTipOff, -1000


#If Sub
;superscript numerals
0::Send, {U+F661}
1::Send, {U+F662}
2::Send, {U+F663}
3::Send, {U+F664}
4::Send, {U+F665}
5::Send, {U+F666}
6::Send, {U+F667}
7::Send, {U+F668}
8::Send, {U+F669}
9::Send, {U+F66A}

;oldstyle numerals
+0::Send, {U+F730}
+1::Send, {U+F731}
+2::Send, {U+F732}
+3::Send, {U+F733}
+4::Send, {U+F734}
+5::Send, {U+F735}
+6::Send, {U+F736}
+7::Send, {U+F737}
+8::Send, {U+F738}
+9::Send, {U+F739}

;Spanish with accents and tilde
o::Send, {U+00F3}
i::Send, {U+00ED}
a::Send, {U+00E1}
e::Send, {U+00E9}
u::Send, {U+00FA}
n::Send, {U+00F1}
^+a::Send, {U+00C1}
^+e::Send, {U+00C9}

;German with umlaut
^+o::Send, {U+00F6}
^+u::Send, {U+00FC}

;Misc symbols
c::Send, {U+00A9} ;copyright symbol
+-::Send, {U+2014} ;em dash
-::Send, {U+2013} ;en dash
+;::Send, {U+201C} ;double curly quote left
+'::Send, {U+201D} ;double curly quote right
`;::Send, {U+2018} ;single curly quote left
'::Send, {U+2019} ;single curly quote right

;Small caps
+a::Send, {U+F761}
+b::Send, {U+F762}
+c::Send, {U+F763}
+d::Send, {U+F764}
+e::Send, {U+F765}
+f::Send, {U+F766}
+g::Send, {U+F767}
+h::Send, {U+F768}
+i::Send, {U+F769}
+j::Send, {U+F76A}
+k::Send, {U+F76B}
+l::Send, {U+F76C}
+m::Send, {U+F76D}
+n::Send, {U+F76E}
+o::Send, {U+F76F}
+p::Send, {U+F770}
+q::Send, {U+F771}
+r::Send, {U+F772}
+s::Send, {U+F773}
+t::Send, {U+F774}
+u::Send, {U+F775}
+v::Send, {U+F776}
+w::Send, {U+F777}
+x::Send, {U+F778}
+y::Send, {U+F779}
+z::Send, {U+F77A}

Basically it allows me to quickly type things like oldstyle numerals, superscripts, small caps, and diacretics without pausing and moving to the mouse. Also, the copyright symbol.

Thanks Rob. I see TextExpander is a monthly subscription... yuck. And not quite what I want either. Typinator night do it... looking into that now. Also cumbersome, as I have to create a script for each substitution.

I'm still hopeful that KM might work. I don't mind the popup; I'll be staring at the keys anyways! :crazy_face:

I'm no PC font/keycode guru -- but these look to be private use characters (and no, I don't know what that means!) so you may need to remap these. Standard Unicode for superscript 1 is 0x00B9, for example, and that works fine directly from KM:

(See the "Token Processing" section of the manual for what's going on there with the % symbols.)

Once you've worked out the "proper" :wink: codes you could make a macro for each, all with the same F12 hotkey, and use KM's conflict palette to manage them (careful naming would let you use your old keystrokes), you could make a macro that paused then used the next keystroke to select the typed character, etc.

Edit to add:
It might depend on what this "one program for professional work" program is. If it ships with its own fonts you might be able to use the codes you have -- try them and see. If it's a Windows program you are running in a VM, things could get very tricky...

I think that this is possible:

  • Create a new macro group that is enabled with F12.
  • Instruct Keyboard Maestro to display a message that the alternative keyboard layout is activated.
  • Inside this macro group create one macro per special character: a types á etc.

Thanks, those private use characters are my own customization. But yes, the Unicode works just fine for those, and they can't be substituted unfortunately!

Ok, like this?

I must be doing something wrong. I tried it without the "U+" as well and no go.

Sorry, on other forums I'm used to being the one helping others... out of my element here.

Screen Shot 2024-04-04 at 19.41.54

1 Like

To use @ALYB's approach, you'd need to use the Insert Text by Typing (or Pasting) action, and have it type/paste the character you want inserted. You wouldn't have to use the unicode, unless you need the unicode itself inserted; you can insert the actual special characters.

I think @ALYB's approach is probably the best; I'd forgotten that you can enable and disable macro groups via hot keys! Another approach would be to just put up an input box, type into it, and then process it when done typing. That's what my approach does:

Download Macro(s): Special Key typer.kmmacros (14 KB)

Macro screenshot

Macro notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System information
  • macOS 14.4.1
  • Keyboard Maestro v11.0.2

But really, go with @ALYB's solution :).


1 Like

Could prompt with list to expose additional characters also work in this case?
prompt with list - expose characters


Great, I think this is the solution. But I would like to use the Unicode characters, since I already know them, and I don't know how to copy-paste from character map (or whatever the Mac equivalent is!).

How do I input the Unicode characters correctly? I've searched for it.

Ok, I think I got it! Let me know if this is the best way. I assume I just duplicate the macros and modify each.

You've used a "Set Variable" action instead of an "Insert Text by Typing" one. And no, you don't need the U+ -- essentially that means "Unicode incoming!", and similarly for four characters wrapped in % symbols as a KM token.

Sample action you can use:

Type Unicode.kmactions (504 Bytes)

1 Like

Got it. I did "Insert Text by Pasting," which seems to do the same. It works perfectly. I got this by typing


and F12 to turn it off.

1 Like

Cool. Now what you can do is set up all your macros with the same hotkey then carefully name them so that the first different character in all the names is the character you are used to pressing. Because they share the same hotkey that'll invoke KM Conflict Palette, which you can navigate from the keyboard by "first different character" in the macros available.

Import these 3, enable them (disable any other F12-triggered macros) and you'll see what I mean:

Unicode Tests Macros.kmmacros (4.2 KB)

So to type "2¹3" you'd press 2 then F12 then 1 then 3

1 Like