A Macro to Enter Accented Characters (Diacritics)

(See the new and improved version below with a numeric menu to select the larger diacritcs displayed above it (just like macOS does it).)

The macOS method of inserting an accented character into your text is to hold down the unaccented character (an "e" for example) until a popup window presents the numbered choices for you.

This works very well and has been the preferred method but some applications (like InDesign and Scrivener) don't recognize the method and simply repeat the key as long as you hold it down.

The alternative method of entering a diacritic is to type one of the handful of dead keys for the particular accent (say, ⌥`) and then the unaccented key to get the diacritic (è, in this case).

But the problem with that approach is remembering which key represents the dead keys for any particular mark.

So this macro runs to the rescue with an approach as efficient as the macOS methods that works in stubborn applications too but doesn't require you to remember anything more than a hot key.

Type the unaccented letter first and then the hot key (the default is ⌃`). A popup close to your cursor will display any options for that letter (or convert letters and punctuation with no options). Click on one and it's entered. Or press Escape to dismiss the option.


Here you can see the popup has been drawn just above the word where an "a" has been typed before the hot key. The display, like the other palettes, enlarges the characters for visibility and adds a slight engraving effect to make them more readable.

It works for ¡esclamations! and ¿question? marks too.

(This macro is part of the Text Toolbox II collection.)

Diacritics.kmmacros (18 KB)

Keyboard Maestro Export


This is a very nice macro. I just made some changes to my keyboard setup which required me deleting my International input (meaning I can no longer type a single quotation mark followed by the letter to get the diacritic), and this might be a good way to simulate that. Thanks for sharing!

You're welcome. Hope it works for you.

New and improved Diacritics Macro adds a numeric menu under the larger diacritics display so you don't have to leave the keyboard to pick one (just like macOS's native version):


Update (28 March 2024): Fixed the indexing bug, reported non-digit keys and added a notification if the macro can't find anything to accent ("Nothing appropriate selected").

Diacritics.kmmacros (18.6 KB)

And here's a version that omits reporting the non-digit key (when expecting a mouse click or number):

Diacritics.kmmacros (18.6 KB)

Update (29 March 2024): This version puts the palette in the top right corner of the active window rather than near the mouse (which may not be where the text insertion point is). That's feasible now with the indexed replacement option (you don't have to mouse over). But if you prefer to use the mouse, you can disable the action that moves the mouse in the macro. This version also minimizes the JavaScript in the Custom HTML Prompt window so the macro is a bit smaller than it would otherwise be.

Diacritics.kmmacros (19.7 KB)

I'm using the PC International keyboard layout and instead of Umlaut-values, I get:

Screenshot 2024-03-27 at 11.23.03

EDIT: When I use the mouse, the ö, ä etc. is inserted. When I type the number below the Umlaut-value, incorrect values are inserted.

I really like this tiny menu. If I remember correctly, there's no way to position it near the text cursor.

Oops, not your keyboard. Mine. I'll fix it when I return to the 'piano' later today.

An alternative would be to type “ to place the umlaut. More intuitive/apt for blind typing. Instead of/as an alternative for the numbers.

Perhaps the locating of the text cursor can be done via ocr?

Fixed in the original post. Thanks for pointing that out. I had mistakenly thought the code was returning the correct value when it was returning the first value.

Not sure what role OCR would play here. The macro is designed for interactive editing. It accents the character before the cursor (whether just typed or just located).

Nothing to remember (hence nothing to be intuited). Just look for what you want among the options and either click on it or use the index number to convert the unaccented character.

The macOS version of this isn't always recognized by applications (which may prefer to simply repeat the key if held down). But this always works.

Perhaps OCR can be used to locate the position the blinking text cursor. Then the tooltip could be positioned above the text cursor.

The location of the popup is controlled by the Custom HTML Prompt and based on the mouse position:

<body data-kmwindow="MOUSEX()-50,MOUSEY()-50,200,150">

So you can change that a fixed position if you prefer or move it under the mouse or put it wherever you want it using those coordinates.

Thanks for your explanation. My reasoning was that it's more logical to position the popup where you are typing rather than where you left the mouse cursor.

You're right and originally I thought they would be the same -- but they aren't. It would be nice to have an action that moved the mouse to the cursor position.

With the index now, I suppose you could have a fixed position. Here's a version that moves the mouse to the top right corner of the window to display the popup:

Diacritics.kmmacros (19.7 KB)

That's sort of half-way there. It's relative to the window but fixed. Alternately you could just position the popup in the same spot on the entire screen with the data-kmwindow coordinates.

1 Like

EDIt: I had this working, but after closing Word I cannot get it working again.

Tried to set the mouse cursor position at the caret position. This version works in Ms Word (but not in BBEdit, TextEdit etc.).

Where can I set the vertical position of the html window 20 (or 50?) above (below) the current position, so that it does not overlap the text? Tried to add 20 to the Y position, but as always: it's not as simple as that :).

BTW: Perhaps it's even nicer to temporarily insert the ◆ in place of the selected letter. Not sure ...

Diacritics.kmmacros (29.5 KB)

OCR cannot "locate" anything. All it does is tell you what text is inside a box that you specify. And what's more, that text cursor is flashing, so it's not always there. And even worse, it's not a hard flash, it's a gradual fade in/out. I've tried using OCR to read the text cursor and it fails about 95% of the time because the cursor is not the same brightness as the text around it, due to the fading issue.

That's set by the data-kmwindow arguments:

But it is the mouse position. Sorry, I can't test (not a Word user) but it should be as simple as that.

I did try running it in BBEdit, adding a test for an empty return variable and trying the negative of the image (to handle light/dark display modes). But still empty.

I've used the location of the caps lock indicator to position the html near the caret:

Test - Find caret position via caps lock indicator.kmmacros (34.3 KB)
It needs some tuning to move the html window a little more down.

Ah, I've found it where I had to change the Y position. And I've moved the action to turn off the caps lock to a more logical place. Now everything is fine :slight_smile:.

Test - Find caret position via caps lock indicator.kmmacros (34.3 KB)

1 Like

I tried this on Ventura with BBEdit but didn't see a Caps Lock icon on my screen. I assume this is a Sonoma-only solution but correct me if I'm wrong. :slightly_smiling_face:

Yes, it's a Sonoma-only feature.


1 Like