Trim whitespace does not work on clipboard content

I am trying to remove the first white space character that appears at the start of my clipboard content but the action does not seem to be working.

When I paste the current clipboard, I see that the first white space still remains. Could you help me understand what might be causing this behavior?

Here's how my setup looks at the moment:

Thank you.

I have also tried using substring of a clipboard and use regular expression actions as suggested by AI but those actions don't seem to be removing the first white space character either:

https://www.perplexity.ai/search/how-to-remove-the-first-charac-07XY_NHrSteoWKw2mJ6aJw

Just the first character? Do you want to remove all the whitespace or just the first whitespace character? There's a difference.

I'm unable to tell what the Move and Click actions do in your macro. It might be important to know what they are clicking on. For example, you might have them clicking on a button called "Copy to Clipboard."

I've used the same Filter action that you are using, and it works for me (my leading whitespace is removed.) So maybe there's something you're doing wrong. When are you pressing the hotkey CMD-H?

In fact, I can see in the lower part of your Filter action that it indeed has moved the leading whitespace. So my guess is that you are not pressing CMD-H after loading the system clipboard. The way you have written this macro, you have to trigger it EVERY TIME you change your system clipboard. Is that the thing you haven't considered? There is a way to get the macro to trigger differently, so that whitespace is ALWAYS removed automatically when you load the clipboard, but that will add more stuff to your macro.

Thank you for responding.

I solved this issue by adding a quarter of a second delay before running the trim white space action. The second mouse click in my screenshot is the actual copy action. So having some time delay immediately after that but before trimming the white space seems to help:

1 Like

Yes, good deduction. As I wrote, those mouse clicks might have something to do with copying something to the clipboard. And if that copying is being done asynchronously, that explains why you needed to add a little time.

1 Like

It usually does work, so there's something else going on here. What are you copying from and, more importantly, pasting to -- there's a good chance that an over-eager "smart" paste is adding the space for you...

This was what's happening:

Apologies -- for whatever reason, I wasn't seeing that post when I responded. In an attempt to make up for my faux pas...

This is probably because there's no actual "Copy" command in your macro. When you use the "Copy" action the macro will wait for the Clipboard to change (or the Copy to fail because nothing is selected). When, as it appears here, you clicking an interface widget to do the Copy there's no such cue, and KM can have run the Filter action before your app has set the Clipboard.

If you want to remove the hard-coded pause, have a look at the "Pause until..." action -- you could save the value of CLIPBOARDSEED(), do the click, then "Pause until..." CLIPBOARDSEED() is different to the value you saved.

1 Like