How Do I Clear an App's Internal Clipboard

Me and @noisneil are trying a macro for Logic Pro X where it copies a Finder's file path (or the file itself, there's also that option) to the system clipboard, then goes back to Logic and pastes it to create a new track with those settings. This method works as long as I don't hit CMD+C to copy something inside Logic (such as MIDI or audio region).

Once I copy something to the clipboard, the macro runs, but then pastes that other thing I copied (MIDI / Audio region) instead of the Finder's file, even though the Finder's file show up as level 0 inside the clipboard history, so it's the one at the top.

Me and Neil got to the conclusion that this is probably because Logic may have some kind of "internal clipboard" and that is prioritized over the System Clipboard. I even tried using a Named Clipboard, but no luck.

Is there a way to run some kind of script or any other solution to clear that internal clipboard, if this is even a thing?

1 Like

All apps access and share the system clipboard – that's why we can copy and paste from app to app.

As soon as you use ⌘C in Logic Pro X, you overwrite whatever was previously in the system clipboard.

Actually it seems to be a bit more nuanced than that. From what I gather, Logic overrules the system clipboard if anything has been copied within it, even if it was copied before before the latest addition to the system clipboard.

A first experiment might be to see whether the shell command line incantation:

pbcopy < /dev/null 

(which clears the shared system clipboard)

has any impact at all within Logic.

If not, sandboxing seems likely to prevent any external process from getting access to any more local pasteboard that Logic creates – you would probably need to track down something in the Logic UI.

1 Like

The other thing, of course, is to check that you have actually populated the standard clipboard in the way that you intend.

One way of viewing the various types of (textually representable) material in the clipboard is this:

Clipboard Viewer - Macro Library - Keyboard Maestro Discourse

( If, for example, you turn out to be capturing the file path as a public.url or
public.file-url pasteboard item rather than as a public.utf8-plain-text item, then Logic may simply not know how to handle it, and the solution may be a clipboard format conversion )

@iamdannywyatt, try running this :point_up:t3: at the start of the macro as a shell script and see if it works. I know you found a workaround, but I'm still interested to see if this does it.

The macro works as intended when Logic's clipboard is manually cleared (by using the key command Deselect all and then hitting ⌘C), so I think sandboxing is the issue.

Interestingly, Danny can copy and paste these file paths on his old version of Logic but I can't with my new one. He's also on an older OS, so I'm not sure which element has been tightened up, but it seems the sand has been well and truly boxed of late.

Here is the textual information from Finder vs Keyboard Maestro when copying a .wav file to clipboard for me. Copying from Finder has the DAW recognise the file in clipboard and through Keyboard Maestro it does not.

From Finder (paste works):
{
"public.file-url as propertyList": "file:///Users/User/Music/Samples/sample.wav",
"public.file-url as string": "file:///Users/User/Music/Samples/sample.wav",
"public.file-url as data": "file:///Users/User/Music/Samples/sample.wav",
"public.utf16-external-plain-text as propertyList": "sample.wav",
"public.utf8-plain-text as propertyList": "sample.wav",
"public.utf8-plain-text as string": "sample.wav",
"public.utf8-plain-text as data": "sample.wav"
}

From Keyboard Maestro (paste does not work):
{
"public.file-url as propertyList": "file:///Users/User/Music/Samples/sample.wav",
"public.file-url as string": "file:///Users/User/Music/Samples/sample.wav",
"public.file-url as data": "file:///Users/User/Music/Samples/sample.wav",
"org.nspasteboard.source as propertyList": "com.stairways.keyboardmaestro.engine",
"org.nspasteboard.source as string": "com.stairways.keyboardmaestro.engine",
"org.nspasteboard.source as data": "com.stairways.keyboardmaestro.engine"
}

Like this?

image

If so, do I need to make any changes to the menu on the blue cogwheel (top right)?

Yeah exactly. It will clear the clipboard history at the start of the macro. I'm interested to know if this works the same way as copying nothing.

No luck. Didn't work...

1 Like

Could there be something significant in those textual infos I posted above? For example the one from Finder has "public.utf16-external-plain-text as propertyList" which is missing from Keyboard Maestros clipboard.

If we could get the textual information of the clipboards match it would make sense that the DAW would treat the file the same way. And since the copy/paste works from Finder every time it could be the thing that solves the problem.

Is there a way to edit/add textual information of the clipboard?

1 Like

Tell use more about what that means ?

What string exactly do you want to paste ?

  • A full file:// url ?
  • Just a file name ?
  • Something else ?

As @Plush points out, there appears, for example, to be no public.utf8-plain-text content in the clipboard contents which you have assembled through KM.

( public.utf8-plain-text is often the first identifier that an application looks for in the pasteboard)

"It didn't work" as in: Logic is still pasting something else other than the file it's supposed to. So basically that shell "code" didn't solve the issue. The only way to "clear" the app's clipboard is to hit CMD+C, which is what the macro is doing now and it works.

Basically when I'm using Logic, I want to load a certain "preset" file called Patch. When I open Logic, before I hit CMD+C to copy anything inside the app, if I run my macro, it is able to go to Finder, copy a Patch file and paste into Logic. Once I copy something else inside the app, it no longer pastes the Patch file. Instead, it will keep pasting that other "thing" I copied inside the app.

=

  • A full file:// url ?
  • Just a file name ?
  • Something else ?

We may be able to fix it by placing whatever it is that you are after (one of the above ?) into a public.utf8-plain-text pasteboard item (by script).

(but we do need to know exactly what it is that you want to put in that pasteboard :slight_smile:

Boat missed here because evening has now come down. I'll be back in between 24 and 48 hours, and I'll take another look if no-one else has done it.

I think @iamdannywyatt has his macro working through a workaround, but it's me and @noisneil who have problems with our DAWs (me with Ableton him with Logic) because we are on newer systems and unable to exploit the workaround.

So, to recap we would need to get the textual information of clipboard made by Keyboard Maestros "Set System Clipboard to File Reference" action to match the one that is created by Finder when the file is copied from a Finder window ,so that our DAWs would think that the file is copied from Finder instead by Keyboard Maestro.

I did the textual information macro again and these are the lines that it gave me.

The textual information from Finder copied clipboard is as follows:

{
  "public.file-url as propertyList": "file:///Users/User/Music/Samples/Sample.wav",
  "public.file-url as string": "file:///Users/User/Music/Samples/Sample.wav",
  "public.file-url as data": "file:///Users/User/Music/Samples/Sample.wav",
  "public.utf8-plain-text as string": "Sample.wav",
  "public.utf8-plain-text as data": "Sample.wav"
}

...and the information from Keyboard Maestro is:

{
  "public.utf8-plain-text as string": "/Users/User/Music/Samples/Sample.wav",
  "public.utf8-plain-text as data": "/Users/User/Music/Samples/Sample.wav",
  "org.nspasteboard.source as propertyList": "com.stairways.keyboardmaestro.engine",
  "org.nspasteboard.source as string": "com.stairways.keyboardmaestro.engine",
  "org.nspasteboard.source as data": "com.stairways.keyboardmaestro.engine"
}
1 Like

Hey guys,

Since @ComplexPoint seems to be busy, I've been trying to find a non-scripting solutions to our problem (since I'm no good at scripting). But please if @ComplexPoint you have scriptable solution to this, it would be much appreciated since my workaround is probably slower and not even complete yet.

Anyway, I had been playing around with this AppleScript script command set the clipboard to POSIX file "/Dir/file.wav". After trying it out several times through Keyboard Maestros run AppleScript command I ran it with Apple's own Script Editor and lo and behold it worked for me. I got the file copied to clipboard and it pasted to Ableton every time.

But seemingly for some reason running the script through KM fails every time. So the next best thing was to save the script as an application (.app) and run it with KMs "Activate a Specific Application".

Ok, so this all works (if you try it put 1 second pause before the paste action). But the problem is here that I'm no good at AppleScript and don't know how to pass a variable (which would be the file you specify in KM script) to an .app AppleScript so we could get any file to the clipboard. If possible the script then could be run with KM as shell script like open -n ./Clipboard.app $KMVAR_pathtofile

So if there anyone knows how to pass a variable to AppleScript app, that it would be a big help!

1 Like

I'm out with family and friends for my birthday dinner and have had a few drinks. What does it say about me that I wish I had my MacBook with me so could quickly knock up a macro?!

Great work.

Will be very interested to see if the same thing applies to Logic... When my hangover subsides tomorrow (or next week).

1 Like

Hey Guys,

From what I'm seeing you might want to try Keyboard Maestro's Set Clipboard to File Reference action.

If that doesn't work then there are some AppleScript options.

-Chris

Happy birthday, Neil! It seems you enjoyed it :wink:

It says you need rehab when it comes to macros hahaha

This would be awesome, because then we could rely on copying-pasting, regardless of Logic's version.

Doctors prescribe 2 macros a day, every 4 hours, for 7 days.

1 Like

For the macro that @noisneil created, he actually used that action. It works on my version of Logic and macOS, but it doesn't work for him. So I believe another approach is needed to make it work on his computer.