Toggle Between Named and History Clipboard, and Bring to Front if Not Focused

Hi, I'd like to toggle between Clipboard History Switcher and Named Clipboard Switcher with one hot key trigger (Hyper-V). The ideal flow that I want is something akin of (pseudocode):

# Activating
if CLIPBOARD_SWITCHER not active
  activate HISTORY_CLIPBOARD
else
  if CLIPBOARD_SWITCHER is active but not IS_FOCUSED
    # focus the switcher whatever mode it is in
    do IS_FOCUSED to CLIPBOARD_SWITCHER
  else
    if CLIPBOARD_SWITCHER TITLE contains "History"
      activate NAMED_SWITCHER
    else
      activate HISTORY_SWITCHER
    end if
  end if
end if

# Deactivating
if CLIPBOARD_SWITCHER has IS_FOCUSED
  USER press ESC on HARDWARE_KEYBOARD
else
  USER do IS_FOCUSED to CLIPBOARD_SWITCHER
  USER press ESC on HARDWARE_KEYBOARD
end if

The problem I am facing is, I cannot detect whether switcher window is focused or not. I am looking for the solution in which I don't need to reach for my mouse (hence, Keyboard Maestro).


Other alternative I can think of is to assign Hyper-T, triggering AppleScript to AXPress the checkbox 1 of window {Named Clipboard Switcher|Clipboard History Switcher}. Derived from this thread:

but it is not ideal, because I cannot find a way to only assign Hyper-T to toggle Named/History only when the switcher active.


Is there solution to either:

  • with a single hotkey, I can trigger Clipboard History and toggle to Named Clipboard. Which also bring them back to focus
  • or, detect whether Clipboard Switcher is focused or not. If yes, a hotkey will make it toggle between Named/History.

Thanks :slight_smile:

Hey @ybbond,

Interesting idea. I might replace my own Clipboard History Macro with this one.

-Chris


Toggle Clipboard History Switcher & Named Clipboard Switcher v1.00.kmmacros (9.7 KB)

2 Likes

Thanks for this :smiley:

Closing then opening the switcher is a nice trick that surely makes it back to focus.

Your approach gave me idea, and modified the macro a little.

  • I removed closing the switcher via AppleScript's AXPress
  • I added "Activate Clipboard HIstory Switcher" if in case "ClipboardHistorySwitcher" vice versa the Named.

I do not know how to benchmark the difference, but I believe AppleScript is slower than using Keyboard Maestro's built-in action, no?

Toggle Clipboard History Switcher & Named Clipboard Switcher v1.01.kmmacros (9.6 KB)

This is quite possible, because Keyboard Maestro uses osascript to run AppleScripts and is a trifle slow.

-Chris