Q: If clipboard contains any Japanese character, then

I'm trying to find a way to execute a macro only if the clipboard contains a Japanese (or any double-byte) character. It is possible? If yes, any help would be appreciated.

Hey There,

You can search the clipboard with a Japanese language specific regular expression.

Search Clipboard action

Regular Expressions for Japanese Text

I've tested against Hiragana and Katakana, and the given patterns work – although the Unicode code point numbers need to be enclosed in curly-brackets.

All four of these work in both BBEdit and Keyboard Maestro:

Unicode code points regex    : [\x{3041}-\x{3096}]
Unicode block property regex : \p{Hiragana}
Unicode code points regex: [\x{30A0}-\x{30FF}]
Unicode block property regex: \p{Katakana}

You can build an aggregate pattern like this:



Thanks a lot Chris,
It works, and I also added {Han} for kanjis.
Now I have to figure out the last part : executing macro A if the clipboard contains Japanese characters works... but executing macro B if it does not contain Japanese characters doesn't work since I get an error message and the workflow stops.



Any idea?

Try changing JapaneseText to local_JapaneseText, so it is deleted after every run.

JapaneseText is global, so it stays in Keyboard Maestro's variable space unless/until you deliberately delete it or zero-it-out.

See the Variables user manual section, and look for the “local” section.

If that doesn't fix it I'll actually test a solution.  :sunglasses:


It tried but it didn't work, I still get the same error message. :frowning:

Okay, this is easy to fix.

(I forgot) the key to this is in the little gear menu on the upper right of the search action.


You need to turn OFF the “Failure Aborts Macro” and “Notify on Failure” items.

Japanese Detection Tool.kmmacros (7.8 KB)


Thank you very much Chris, problem solved! :slight_smile:

1 Like

Why extract the Japanese characters into a variable if you just want to know if the clipboard has any? You can directly test the clipboard contents with a regex match:


Thank you Peter, I didn't know that regex could be used in this "If... then" action, I thought it was only for plain text.

Peter, I just tried with your solution and it didn't work. Have you tested on your side?

Yes, it works if I copy “ひらがな” into the clipboard (taken randomly from the Wikipedia Hiragana page).

Make sure you are using “matches” as the condition.

My mistake, I used "contains". Thanks a lot!