How to Detect When Clipboard Has Changed [Example]

MACRO:   [CB] How to Detect When Clipboard Has Changed [Example]

~~~ VER: 1.1    2016-08-31 ~~~

2016-08-31 18:14 CT (Wed)

DOWNLOAD:

[CB] How to Detect When Clipboard Has Changed [Example].kmmacros (8.3 KB)


You may also be interested in this, shown below:

Pause Until Clipboard Has Changed


ReleaseNotes

Author.@JMichaelTX

USE CASE:

  • Used to determine IF the user had made a selection PRIOR to running a macro
  • If you use "⌘C" in a "Type a Keystroke" Action, it will return immedately, regardless of the user's selection (or no selection)
  • Then you don't know if the Clipboard is from the user's selection, or just the prior (unchanged) Clipboard.
  • If you use the "COPY" Action, by default it will fail, and abort the Macro, after its timeout if the user had not made a selection.

How To Test This Macro

  • Test #1: Click on a blank area in any app to make sure nothing is selected, and trigger this macro.
  • Test #2: Select some text anywhere, and trigger this macro.

COPY METHODS:

  1. Use ⌘C with a short pause (0.5)
    OR
  2. Use COPY Action, but set Action Options:
    • Uncheck "Tiimeout Aborts Macro"
    • Set "Action Timeout" to short pause

The macro is setup to use method #1.

REFERENCES:

See this KM Wiki article:
function:CLIPBOARDSEED [Keyboard Maestro Wiki]


Example Results

7 Likes

wow, most excellent, really appreciate it, solid logic, still don’t know much of whats available here (KBM) since moving over from QK’s but it’s great to be with a live community and such strong programming. cheers.
( I know there’s a LOT for me to discover )

1 Like

Nice, deleting the variables after running the macro, not cluttering up the variables, absolutely awesome, I would have never known you could do that had you not been gracious enough to read my post AND share that great key.
~

How did you know to use CLIPBOARDSEED()
is there a list of calculation ‘variables’ that can be used there?

The KM developer, @peternlewis, actually pointed out use of that function some time ago.

If you mean "functions", then yes:

  1. In the KM Editor, goto Edit > Insert Functions
    .

    .
  2. For a complete list with details, see Functions [Keyboard Maestro Wiki]
2 Likes

WOOF! alright then, Thanx JMichael !

Here's another example waiting until Clipboard has Changed:

Pause Until Clipboard Has Changed

image

3 Likes

Hmpppph. I imported the macro, set a hotkey combination trigger, then tried invoking it both with and without text being selected and I always get:

"The Clipboard has NOT CHANGED."

As a relative newb, I can't seem to figure out how to get the example to work properly.

I just test this macro again, and it is still working for me.
Please make sure you are actually select text (not an image) before you trigger the macro.

If you still can not get it to work, please let us know your environment:

  1. what app you are using to test.
  2. Versions of KM and macOS

I'm using KM 9.0.5 and MacOS 10.15.4. It doesn't seem to work in any application I've tried: BBEdit, Brave browser, Messages...

I do know that text is being placed on the clipboard when I have something selected, as I can place the proper copied text if I do a subsequent paste after running the macro. However, it always gives me the "The Clipboard has NOT CHANGED." dialog.

Perhaps this is an issue with macOS Catalina interacting with the KM CLIPBOARDSEED() function. But that's just a guess. Perhaps @peternlewis can advise us.

Anything is possible in Catalina.

Write a macro like:

image

And then run it, and watch the value of the variable name (note that the editor does not see the CLIPBOARDSEED function value, so you have to actually run it to see the changes.

Then copy some things and see if it changes.

1 Like

How come I get another PAUSE statement displayed here?

hello, can you share your macro file?

Hey John,

Who are you asking?

@JMichaelTX's macro is available in Post #1password

-Chris