I’m finding that macros which contain text strings are polluting the system clipboard. For example, if I copy some text, then use a KB macro which takes me to a specific place I’ve specified, then try to paste the text I’d copied, it’s gone - replaced by the text from the KB macro!
Can KB be changed so it uses an alternate/internal clipboard or something for macro data, leaving the OS X clipboard intact? I’d think this would be easy since KB manages multiple clipboards as part of its feature set.
This is a hassle as I use KB to take me to places or do things, after which I want to paste data I’d copied previously. I don’t understand why KB needs to use the system clipboard to store its internal macro data.
I hope this can be fixed.
Keyboard Maestro does have it’s own ‘Named’ clipboards that you can use. I am guessing that your KM macro that takes you to a specific place is doing some copying and pasting. If this is true, change that macro to copy to a KM named clipboard and paste from that named clipboard. That way the system clipboard is never touched and will still contain what you last copied.
. . . Stephen
OSX has only one clipboard. All items copied and pasted go through that gateway.
KM’s multiple “clipboards” are merely storage spaces that permit the same data types as the clipboard.
Moving something to and from one of those spaces to or from an app requires the System Pasteboard to be the gateway.
There’s nothing stopping you from saving and restoring the System Clipboard in your macros.
Some apps are AppleScriptable in ways such that the clipboard can be circumvented.
Sometimes text fields can be accessed with AppleScript and System Events - and again the Clipboard can be circumvented.
Since you haven’t posted an example macro demonstrating your problem, it’s difficult to give more advice.
The System Clipboard is always touched, because IT is the gate through which copy & paste must travel.
Try copying to a named clipboard and then pasting directly from the System Clipboard. You’ll find that what was copied to the named one comes out of the System one.
In order to make this sort of thing work you first have to SAVE the contents of the System Clipboard and then restore it once your operation is complete.
@ccstone describes why the clipboard is modified and why it is unavoidable for any action that copies or pastes, and why copying and pasting is unavoidable for almost all applications.
The reason Keyboard Maestro does not restore the clipboard is described on the wiki FAQ at Why is the clipboard not restored after any clipboard action? which I will repeat here:
Keyboard Maestro does not (automatically) restore the system clipboard after any operation that uses it (Insert Text by Pasting, Copy to or Paste from Named Clipboard, etc) because it cannot be done without incurring a race condition which will sometimes give the wrong results.
The reason is that while the clipboard can be read or set at any time, Copy or Paste can only be done via the Keyboard Maestro event queue (the keyword being “queue”). There is no way to know for sure when the application has processed the Command-V for a Paste operation, and thus no way to know when to restore the clipboard to its original value. If the system clipboard is restored too early, the wrong thing will be Pasted. If the system clipboard is restored too late, you may have already copied something else (manually or via another macro).
Instead, Keyboard Maestro provides a clipboard history and gives you control. Most of the time, you wont be using the clipboard and wont notice that it has been replaced, and if you do need it, you can get the old value ack from the clipboard history. But if a macro is used where you frequently are finding that you need the system clipboard preserved, then Keyboard Maestro provides the tools for this. After your clipboard mangling action, add an appropriately long Pause followed by a Delete Current Clipboard action. The length of the Pause will depend on the target application and the speed of your Mac at that moment, and you will have to be aware that there is a period of time where you should not copy something.
See also the question When should I use Insert Text by Typing instead of by Pasting?