"Insert text by pasting" seems to recreate clipboard, is that expected?

I want to paste and send a message whenever the clipboard is updated, so I have this workflow in place:

  • Trigger: clipboard change
  • Actions: set the clipboard text to a variable -> replace periods with newlines -> paste the variable text -> simulate enter key to send the message.

On theory this should work just once, but the messages seem to be sent multiple times, infinitely.

Is this happening because the "Insert text by pasting" action recreates the system clipboard behind the scenes, thus triggering the workflow multiple times?

If yes, is there a way to avoid this?

Some additional context on the temporary variable PasteOnActiveChat: I use that instead of modifying periods directly in the clipboard because I don't want to trigger the workflow more than once.

You're triggering on clipboard change, and you're changing the clipboard (the paste action modifies the clipboard), so running infinitely seems to be the expected behavior, if I'm reading it correctly.

Use an Insert Text by Typing action, and it won't modify the clipboard. Alternatively, disable your macro as step one (it won't stop the current execution), then delete the current clipboard after you paste it, and then reactivate the macro as the last step. (That's a theory, I think it'd work :)).

-rob.

1 Like

Alternatively, disable your macro as step one (it won't stop the current execution), then delete the current clipboard after you paste it, and then reactivate the macro as the last step. (That's a theory, I think it'd work :))

I don't understand the disable and enable steps, but this works great! Thank you. :slight_smile:

What don't you understand? Basically, we're telling the macro to disable itself after it starts—so any future clipboard changes are ignored. Then the macro does its work, deletes the new pasteboard it created, and reactivates itself.

After I wrote this an walked out for the evening, it struck me that using a semaphore lock would also work. Specifically, this bit:

  • You can also cause all additional macro instances to be immediately cancelled by setting a very short timeout (1 hundredth of a second) for the Semaphore Lock Action. When the Semaphore Local Action times out, it cancels the pending execution of that macro instance.

So add the lock, set it to have a very short timeout, and it should cancel the pending execution of the same macro, caused by the clipboard change.

-rob.

1 Like

Oh, this part clarifies it! I didn't realize that the ongoing run of the macro will complete, even though it's disabled. Thank you.