Safari - Detect Whether Focus is Within a Text Field

I have a few typed string triggers set up for use in Safari (for example, typing 'yt' takes me to YouTube). However, I don't want these triggers to work if I'm in a text field, so that I can type something like "gigabytes" without triggering the macro.

This would be easy to wrap inside an IF... but I don't know how to tell KM to detect if I'm inside a text field. Thoughts?

Hey @brijazz,

You can't.

Unfortunately the macOS doesn't have a public API for Peter to reliably detect such things.

Typed triggers are best used for text-expansion macros and made unique enough that they won't get activated during normal typing.

For instance:

'yt; ' or ';yt ' (less the quotes)

So L then


That's pretty near as fast as your other trigger and solves the problem.

Alternatively you could use a conflict palette for your macros.

Make it a one action palette and give the different sites unique 1 letter/number prefixes to make type-selecting the desired macro simple.

Open Website in Front Browser @ccstone Macros.kmmacros (6.9 KB)


Or you could use a Conflict Palette instead.

Or you could use a Prompt With List action and really go-to-town.

You have many options.


Thanks, @ccstone. I usually go with an ! in front of my typed strings but was just trying to shave off a keystroke (I know, I know...).

Believe me I get this. I'm very particular about efficiency.