Restoring clipboard loses important information

I'm stuck on how to fully restore the clipboard - perhaps this isn't possible.

The main app this is an issue for is OneNote. If I copy several pages in OneNote they will paste correctly as pages (not text content). But when I restore the keyboard in KM, then paste, it now pastes as formatted text content, not as OneNote pages.

It seems clear there is some keyboard information being lost. I believe I've noticed this for other apps as well. Is there a workaround for this or a way to fully preserve the keyboard?

Did you mean "Clipboard"? If not I don't understand the use of "keyboard" here.

If by "restore" you mean make a previous Clipboard in the Clipboard History be the current System Clipboard, then using Delete Past Clipboard action with a clipboard number of "0" as many times as necessary to make the target Clipboard be the current clipboard.

You could also use a Named Clipboard to save the current System Clipboard (when I has the OneNote data), and the when you want to restore it, use the Copy Clipboard to Clipboard action.

1 Like

Thanks for the reply. Tried all of these ideas - they all have the same effect. When KM tries to save the current clipboard or restore it in any of these ways, whatever critical metadata on the clipboard is saying "these are pages, not just text data" is not getting preserved.

When I paste from a historical clipboard in KM it has the same effect. So it seems KM is not capable of fully representing the clipboard in this case.

That would be a great feature to have! I run into this fairly often when trying to paste from a past clipboard and when using "insert by pasting" then trying to restore a past clipboard.

While it is possible KM has some edge case bug, I doubt it.
More likely is that when you switch from OneNote to any other app (like KM), then OneNote puts something different on the clipboard. Many apps do this.

You can confirm by using a tool that will view the clipboard.
I use this one, available free in the Apple Mac Store:

Clipboard Viewer
https://langui.net/clipboard-viewer/

That's helpful, I tried out this tool. As far as I can see, when OneNote has content in the clipboard, it does not change when switching between or pasting in apps, e.g. OneNote to Stickynotes.

But if I copy a page in ON, then perform a paste from the first item (current clipboard) in KM's Clipboard History, the clipboard is immediately substantially changed. Some parts are preserved but others are not.

So the problem seems to be that KM modifies the clipboard and doesn't preserve it in its original state. I would think that pasting the first thing in Clipboard History would not substantially modify the current keyboard.

I'm attaching two images - the first is Before, right after copying a page in ON. The second is After, right after pasting a page via the KM keyboard history. public.html is precisely preserved but other things are different, e.g. "com.microsoft.DataObject" is no longer in the left-hand list.

I don't know enough about clipboards to determine exactly which difference causes the paste to fail (or rather to paste as text, not a page), but for sure KM is not restoring an exact copy on clipboard operations.

I appreciate your insights and if you have an idea of why KM has to modify the keyboard when restoring it instead of using an exact copy, I am interested!

Some apps include information in the clipboard that cannot be preserved (either by marking it not to be preserved, or by having it explicitly excluded by Keyboard Maestro to avoid issues or crashes in the application).

It is caused by poor behaviour on the part of the application - changing its behaviour (or crashing) when specific flavors are read or including data that cannot be preserved safely on the clipboard.

Unfortunately, Microsoft is very prone to this, behaving oddly when various clipboard fields are read, so there are multiple exclusions for Microsoft flavors.

It doesn't matter how the clipboard is restored, these flavors can't be preserved and are lost.

Ok - that's helpful but unfortunate. I figured there must be a reason KM can't restore this data. That makes sense to me - thanks for the help.

Thanks, Peter.
Do you have a list of these apps that provide a clipboard that are "explicitly excluded by Keyboard Maestro to avoid issues or crashes in the application"?

Applications are not excluded, flavors are. By default:

  • dyn.agk8ywxw2ea
  • dyn.ah62d4rv4gk8ycwndkk
  • dyn.ah62d4rv4gu8zaxcxmuufa4dtsv1y24psqzggc8pfsk
  • dyn.ah62d4rv4gk8y2xwpnq
  • dyn.ah62d4rv4gk8y8wwqmq
  • dyn.agk8y2xwpnq
  • dyn.agk8y8wwqmq
  • dyn.ah62d4rv4gk81g7d3ru
  • dyn.agk81n65yru
  • com.adobe.illustrator.aicb
  • com.adobe.illustrator.hfs
  • dyn.agk8ynxncnq
  • dyn.ah62d4rv4gk8ynxncnq
  • com.microsoft.Link-Source
  • com.microsoft.ObjectLink
  • com.microsoft.DataObject
  • dyn.ah62d4qmxhk4d425try1g44pdsm11g55gsu1e82xnqzv1kxdmr3zu
  • dyn.ah62d4qmxhk4d425try1g44pdsm11g55gsu1e24psrq0zg55zsmv0n
  • dyn.ah62d4qmxhk4d425try1g44pdsm11g55gsu1ek2pyqfh0e4xfqr4a

You can affect them, either replacing the list entirely or adding to them as described in the Preferences user manual section.

@peter, that sounds promising. I searched down that page for anything mentioning "clipboard" and didn't find anything about exclusions / inclusions of certain flavors - would you be able to point more specifically to where that information can be found?

Confirmed -- I did not find anything on the KM Wiki page about exclusions / inclusions of certain flavors, except for a specific Microsoft exclusion.

No it doesn't, because any flavors that are ignored, are ignored for a reason. Not ignoring them will produce different bad results.

I have added it to the wiki.

Ignored Clipboard Flavors

You can add additional clipboard flavors to be ignored using:

defaults write com.stairways.keyboardmaestro.engine ExtraIgnoredClipboardFlavors "com.whatever.badflavor"

The string should be a bar (|) separated list of flavors (technically a regular expression). These flavors will be excluded from the clipboard when Keyboard Maestro reads the clipboard.

You can also write to IgnoredClipboardFlavors, which will set the entire list of ignored clipboard flavors, but that is a bad idea since the flavors that are ignored, are ignored for a reason, and overwriting the list will produce negative results.

1 Like