Achieve try on error end try structure in KM

I want to check if the filename string of selection in finder contains chinese characters. If it is true, then, else ...
Cause I cannot find a way to use regex in applescript. I use [ search varaible using regex ( \p{Han}+ ) macro ] in KM. If the output is not empty then... else...
But if the string doesn't contain chinese characters, the KM display error notification, and cancel the macro.
If it's in applescript, I can use try on error end try structure.
Try
[ search varaible using regex ( \p{Han}+ ) macro ]
set findcn to true
on error
set findcn to false
end try
Can I achieve this in KM? Which macro in KM can help me do this? Hope someone can help me.
check if contains chinese characters v1.kmmacros (3.4 KB)

I think it would be easier to use an If…Then action with a RegEx match test. Example:


If Then with regex <C7E2 200302T110228>.kmmacros (3.8 KB)



Concerning the Search action: It depends on the setting of the action, if it will abort the macro or not. Open the Gear menu of the action and change the setting. See this.

1 Like

This works perfectly. Never thought can use if in this way. Very impressive. Thank you very much.

1 Like

If you don't know an action by heart, always check the Help in the Gear menu:

Screen Shot 2020-03-02 at 17.00.10-pty-fs8

In this case the Help leads you to this Wiki article, where you find a list of possible conditions.