How to Detect NULL Values

I match a NULL value by regular expression and it is not empty string, how do I set the condition to detect it

Have you got an example of what you are trying to do in KM? Because the above looks rather complicated for what I suspect could be done in another, simpler, way.

It is still the same problem as last time.

I detect the presence of the image by several cases.

When the NULL value is matched it means there is an image in the clipboard.

If it is not matched, it means there is no image.

But I have no way to detect it in Keyboard Maestro.

Screen Recording 2022-10-02 at 21.49.44.2022-10-02 21_56_25

Have you tried the "If" condition "clipboard does contain an image" or "clipboard does not contain an image"?

clipImage

Yes. It is not a image, it is a list that cannot be directly identified, which was the problem last time.

It doesn’t matter. I just tried to solve it.

1 Like

Yes -- sorry about that, I realised my mistake 5 minutes ago! It was your

it means there is an image in the clipboard

...that threw me.

Glad you've solved it!

1 Like

Hey @jone_smith,

When asking for this sort of help please always include the simplest possible test-case macro that demonstrates the problem – and/or a link to your regex101.com test page.

It's waay better to test than to guess.

Take Care,
Chris

(Keyboard Maestro Moderator)

There are four cases here:

  1. a picture below the text (it is not a picture, but a file address)

  2. a picture in the middle of the text

  3. a direct copy of the picture without the text, i.e. blank, which I detect with ^$ (to put all cases together, so I just replace blank with other cases)

  4. just the text, without the picture (in this case, by (? <=\n$). *|^$ expression can't match any value)

The first three cases, you can match the NULL value, only the last case can't be matched, which means I just need to detect the NULL value to match whether the picture is copied (it's not a picture, but a file link)

Detect NULL
I can't detect this value directly by Search System Clipboard Using Regular Expression (ignoring case) method.

So I use another method Search and Replace System Clipboard Using Regular Expression (ignoring case) to replace it first and then query it. It doesn't look very straightforward, but it works for me.

Detect NUL.kmmacros (11 KB)

Image

My goal was to extract the image addresses from the script provided to me by @ComplexPoint. The process is complicated because I use a software called Eudic English dictionary, which is not in a regular format and cannot be read directly by the clipboard. But one thing is strange, when I drag the image directly to Keyboard Maestro, it can read the address of this image.I think there is a simpler way, but I don't know how to do it.

Screen Recording 2022-10-05 at 13.53.24.2022-10-05 13_55_46

Here is the link to the entire question.

Jone

1 Like

I still think you're going about this the wrong way.

From the clipboard data you supplied earlier, it looks like there will only be an image when there's an image link. So try searching for

"public.html作为数据": "<img src=\"file:///var/folders/

...or similar. If that's true -- image. If not -- no image.

Otherwise, I think it's confusion about regex101's use of NULL. I think they use that to indicate "the match group is an empty string" so you could try the usual KM regex->variables then test the variables with "If... is empty".

1 Like

Hi, Nige_S, thanks for the suggestion, I have adopted another method to get the image directly from the screenshot, it is easier than the previous method and does not require scripting. I'm learning javascript and we can discuss together on json scripting later. :smile: Have a good day.