Why does the Test Macro (is empty?) not show the KM Display window, when nothing has been copied and the Current Clipboard still has a string ("add")?
This test is necessary for constructing a macro with 2 braches:
A: Get DocTTL, PATH, and some TEXT of a file → Clipboard (this macro exists already)
B: Get DocTTL, PATH, no TEXT → Clipboard
First to test if something has been copied, and here 1 branch doesn't return anything when CurrentClipboard still has a string: "add"
...but with the names of your macro and Named Clipboard substituted. KM's Notifications are invaluable when debugging -- you should turn them on and pay attention to them.
Note that you are not testing for an empty clipboard but for a clipboard that doesn't contain text -- but it might have an image. That may not matter here, but watch out for it.
You'll want to play with the "Copy to Named Clipboard" Action's "Timeout" setting so that it is long enough to allow a successful Copy in your slowest-to-respond apps but not so long it gets annoying waiting for your macro to complete.
I've added a couple of Actions to show that the Named Clipboard is not set to empty when there is nothing to Copy -- its previous contents remain, unchanged.
The only reason to use a Named Clipboard in your macro above is if you want to use what you Copied in a different macro later. "Copy to Named Clipboard" is a two-part Action, Copying to the System Clipboard then copying the contents of System Clipboard to the Named Clipboard -- all Copy and Paste is done via the System Clipboard. So you might as well replace your "Copy to Named..." and "Set Variable..." Actions with:
Even better, use a Local variable because you don't have to reset it -- if it isn't set during the "Try" block it won't exist and will later evaluate to an empty string:
So far so very good,
Only it is maybe unexpected, that
BRANCH-A with BODY is very fast,
BRANCH-B however very slow, about 11 sec!
So the process to check if the %temporary Clipboard% exists,
and then at the beginning of BRANCH-B: "Delete past clipboard 1" takes some time.
Maybe after all, some kind of integration with the IF function would be faster?
It's easier if you don't over-complicate things and also always stick to Local variables unless you absolutely need either persistence or greater scope.
Here's your macro, simplified and working for TextEdit:
I say "...for TextEdit" because different apps behave in different ways when you try to Copy when nothing is selected -- Obsidian, for example, Copies the line the insertion point is in.
Yepp;
I waited for the input, but now I'm so tired I need a rest, back very soon :_)
But when I think about it, it could work, it probably does too!
Debugging any macro would be something, somehow there is this way of executing a macro step by step and observe exactly what's happening.
But I'm not good at it, tried it once. I'll check it on YT…
Yes, because if you tell an application to do something and it can't then it should return an error, making your computer beep at you.
If you don't want that then you'll need a different approach. The more usual way of doing what you want is to see if something can be Copied and proceed accordingly. For many apps you can do that by checking whether the Copy menu item is enabled: