How to add condition: IF BODY = empty: proceed! (Text Macro)

With the help of our KM forum members I was able to continue on this TTL & URL+quote-from-the-text (= ‘BODY’) macro.
(Works on both FFOX and Opera)

So now I have 2 macros,

  • 1 without the quote-from-the-text and the other
  • 1 WITH the quote-from-the-text

They all provide the TTL & URL.

If there would be only 1 macro, which proceeds even if there is no quote-from-the-text, but this is above my level :slight_smile:

Maybe this CLIPBOARDSEED, but how to implement?

  1. Get the selection quickly even if empty - Questions & Suggestions - Keyboard Maestro Discourse
  1. This one gave me the same results - for either way: empty click or selection. from 2018

    How to Detect When Clipboard Has Changed [Example] - Macro Library - Keyboard Maestro Discourse

Any suggestions?

/
best regards,
OmarKN

N8 FFOX- Opera TTL & URL & BODY.kmmacros (12 KB)

CLIPBOARDSEED() changes when the System Clipboard is changed -- so save the seed, do the copy, compare the current seed to the old one. If it is the same then nothing new was Copied:

Note the "nothing new" bit! If you select some text on your web page and Copy it and then run your macro without changing the selection, the Clipboard won't change so VarBODY will be blank.

The 1st part is ok, but the second part, when nothing was selected/ copied, isn’t.
I set 2 different sounds after.

(The intention is for the main macro (Get TTL URL BODY) to run either way, if something has been selected or not. The main macro fails when it can’t find a BODY text.)

I’d think it can be tested in Firefox as well as in Opera.

S2 COPY or not CBSeed oE (not working).kmmacros (17 KB)

Then something is being copied, even when nothing is selected. If it is like Safari then that could be an empty string -- so use that as your condition rather than CLIPBOARDSEED():

If that's the case you may not need the test at all. If the only difference in your two branches is the insertion or not of the copied web text then don't branch -- just insert the Named Clipboard, which will be either text or an empty string.

Thank you, @Nige_S for your input.

Always surprised how Keyboard Maestro (with the right know-how) can solve problems.

  1. Regarding the example above: This works for Safari (and probably G Chrome) but not for Opera (FFOX).

  2. Re: inserting a Named Clipboard, which will be either text or an empty string. I’ve tried this earlier, but it doesn’t work for Opera (FFOX).

With Opera (and FFOX), when nothing is copied the Display (Nothing copied) doesn’t come up, so no flow.

If this cannot be addressed by KM, and the user will have to employ 2 different triggers, then this is good enough. :slight_smile:

/okn

But you also have to define the problem.

You have the tools -- find out what's happening. Use KM's Clipboard History Switcher and/or the Named Clipboard Switcher to see what happens when you Copy from Opera when nothing is selected, then base your tests on that. Remember that you can test multiple Conditions and nest "If" actions, so you can easily do "if the frontmost app is Opera then do this test, if it is Firefox do that test, otherwise do the other test".

And you have to do this for yourself. Different apps, even different versions of the same app, can behave differently when Copying with nothing selected. So this works for me in Safari, Opera and Firefox:

Was Something Copied.kmactions (3.7 KB)

...but may not work for you.

Remember that when there really is "nothing to Copy" then the "Copy" action will fail -- and, by default, that will be after 10 seconds and will abort your macro. So you need to change the action's Options, allowing long enough for a "big" Copy but not so long that it gets annoying:

2 Likes

Yes, it works on all 4 Browsers, Opera, FFOX, Safari, G Chrome!
Thank you.