Determining if Clipboard History Switcher is open

Hello All,

I am trying to figure out a BETTER way of checking to see if the Clipboard History Switcher is already open/at-front. There is only 1 way that I know of to test this (explained below).

I have a macro setup for my mouse's middle-click that will pull up the history switcher OR if it is already open will paste the selected item (keystroke: enter).

My 'work-around': IF/THEN like so:

IF (any of the following are true) This screen: [Found Image Condition] contains

(at ~50% precision) in all screens execute the following actions

My 'middle-click' Macro:

If anyone knows of a different, better way of checking if the Clipboard History Switcher is activated please let me know. My work-around does work but is quite a hack, and can be slow (especially when system is under load). It seems like since the Clipboard History Switcher is built-in to KM there would be an easier way of determining this.

I have tried all of the "obvious" methods I could think of: "Is macro 'Activiate Clipboard History Switcher' active" & "Is front window title (or does it contain) 'Clipboard History Switcher' ..." etc. but none seem to work.

Dusting off an old thread...

I had the same question because as I was recently modifying a macro (Insert Text Into Restricted Field) I discovered that the Activate Clipboard History Switcher action is a toggle, not exclusively an activation of the Clipboard History Switcher. @peternlewis confirmed this observation.

In my macro, I want to open the Clipboard History Switcher (or leave it open if it's already open), so I use this:

If Then Else.kmactions (2.2 KB)

Keyboard Maestro Export


2025-04-30 UPDATE: For a simpler solution, see @Nige_S's post below.

3 Likes

That runs very fast and seems to work great on my system. Are you trying to use native Keyboard Maestro actions? Also pretty nice, I haven't used an AppleScript for an If Action suprisinly or at least i don't recall ever doing so.

I love that they are left open personally and hope it stays that way.

P.S. Welcome back, nice to see you active again. I haven't seen you for the past couple weeks.

1 Like

Sorry, @skillet, I don't understand your question. Are you referring to the AppleScript within the IfThenElse action?

If there's a simpler way to detect the status of the Clipboard History Switcher, I'd be happy to learn.

You don't need System Events -- you can query the Engine directly. My version is:

image

5 Likes

Curious what action you use for your "Do Nothing" comment. I am guessing you just renamed a comment.
image

Yep, just a favourited renamed "Comment" action.

1 Like

Thanks, @Nige_S!


UPDATE: See below.

superseded information

After some additional testing...

In my macros I want to unminimize the Clipboard History Switcher if it is minimized.

The following seems to work*, but is there a better way?

Initial State Result*
open, unminimized no change
open, minimized unminimize
not open open unminimized

If Then Else.kmactions (2.4 KB)

Keyboard Maestro Export


I think that'll break if the "Named Clipboard Switcher" is open but minimised. This script should cater for that eventuality as well:

tell application "System Events"
	tell application process "Keyboard Maestro Engine"
		try
			set value of attribute "AXMinimized" of item 1 of (every window whose name is "Clipboard History Switcher") to false
			return 1
		on error
			try
				set value of attribute "AXMinimized" of item 1 of (every window whose name is "Named Clipboard Switcher") to false
			on error
				-- do nothing
			end try
			return 0
		end try
	end tell
end tell

You could do away with the error blocks and use your "get list, if list count > 0" construct if you prefer that more explicit way of doing things.

1 Like

In my testing, it seemed to handle all cases without generating an error. UPDATE: See below.

For me, if I open the "Named Clipboard Switcher" then minimise it the macro needs to be run twice to get "Clipboard History Switcher" to appear.

First run there will be no windows with the name "Clipboard History Switcher" so the script returns 0 and the "Activate..." action executed -- that changes the minimised "Named Clipboard Switcher" to the minimised "Clipboard History Switcher". Second run will unminimise that window.

1 Like

Odd, not for me. I even tried both states of this System Setting just to see if that might affect the testing. UPDATE: See below.

superseded


1 Like

This seems to work here.

tell application id "com.apple.systemevents" to tell application process "Keyboard Maestro Engine"
	if window "Clipboard History Switcher" exists then
		tell application "Keyboard Maestro Engine" to activate
		set value of (attribute "AXMinimized" of window "Clipboard History Switcher") to false
	else
		error
	end if
end tell
2 Likes

My mistake, @Nige_S, I skipped right over that: Named Clipboard Switcher

As usual, you are exactly right!

I downloaded your version and tested it on my mac and it works just as you described. Sorry for the confusion I might have created.


Using your approach, I created this:


Download: Displaying the Clipboard History Switcher or Named Clipboard Switcher.kmmacros (15 KB)

Macro-Image


Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 15.4.1 (24E263)
  • Keyboard Maestro v11.0.3

1 Like