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.
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:
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.
@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?
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.