Copy clipboard to selected folders

I can't seem to figure this out no matter what...

I have a main folder with some files and I want to be able to select those files and copy them to the clipboard.

Then I go and select a bunch of folders and run the macro that pastes the clipboard content to each one of those folders (using For Each).

But using the Copy action and using %SystemClipboard% shows me an error saying that it's not a full path.

File action failed because source is not a full path %SystemClipboard%

As far as I know, a copied file doesn't bring its path information with it, just the filename and contents, so pasting using KM's Copy File action won't work. But you should be able to just have the macro type Command-v, the Paste command, to paste the contents of the clipboard into each folder.

I haven't tested that, but it seems theoretically right.


It seems that the Paste action doesn't work...

Red rectangle are the original files
Yellow rectangle is the folders where those 3 files are supposed to be copied to
Green rectangle is where they were copied to (and since it's set to For Each it started asking me if I wanted to Skip or Replace the files, so I had to stop it)

This is my only action. Am I missing something here?

Looks like you have to open the folder for the paste command to work—this worked in my testing:


1 Like

Yes I also thought about that, but it seems like a very "intrusive" workflow with folders opening and closing, especially if you are doing this for 100 folders for example...

I was thinking of another solution:
1 - Select all files to be copied and add them to a variable, separated by a comma so we can use the index to target them
2 - Select the destination folders and for each folder, copy each variable index

Now the issue here is that KM needs to know how many indexes the variable has so it only runs X amount of times depending on how many files we have.

I was thinking that when we copy the files it automatically does this calculation, for example if we have 4 files, it will set a certain variable to 4. Then when it's running the For Each action it knows that it needs to run a certain loop 4 times by increasing the index value. So it runs 1 time for index 1 and ads 1 to the index value. Then runs a second time for index 2 (original index + 1), etc, until the index is 4 and after that it breaks from the loop.

I'm assuming we need to use dynamic variables when it comes to the index value.

Does it make sense?
Theoretically it's making sense when I say it. I just need to create the macro, but I was wondering if there was a simpler solution...


Something along these lines (I still need to work on the dynamic variables section, because that's still a bit confusing to me)

EDIT: I added %Return% by mistake. It's supposed to be a comma so we can use the indexes:

===Copy selected files to selected folders.kmmacros (34 KB)

While the dynamic method would work, it strikes me as overly complicated. I'd probably do it like this:

Yes, this still has to flash one folder to the foreground briefly to write the copied files, but after that, it's all in the background and completely invisible. You might have to muck around with some delays (to allow time for file copies—not sure what happens if you have 10 huge files on the clipboard), but that's the whole macro.

The cp -r command copies both files and folders, as if there are applications on the clipboard, they look like folders.


1 Like

I will try this as well, even though I still want to fully understand the dynamic variables structure, because right now it seems a bit weird how we have to set them up (I started this topic because of that and I'm reading it now - Dynamic variable - #3 by Zabobon)

I think this is probably one of the issues I see with using the script you shared, because we never know how much time we need until we run the next batch of files, unless it works in parallel, meaning that if the first loop is still copying huge files, it won't mess with the second loop copying files to the second folder?

I can even remove the last action to delete the temporary folder to avoid an additional issue

There are ways to check when the file copy is done, but after doing some testing today, your method has a quirk: You can't tell when the initial paste is done. That's because, for whatever reason, as soon as you press Command-V, the folder reports that all files have been copied to it, even though that's not true.

The way I usually test to see if a file copy is done is to just run the du -s command repeatedly, with a small gap between each run. When the numbers stop changing, the copy is done.

But with Command-V, the instant those keys are pressed, du -s reports the full folder size. That makes it really hard to wait until the initial pasting is done before proceeding. The only way I figured to do it was manually—a fake progress bar appears onscreen, and you press 'c' when you see that the Finder's copy window goes away:

After that, though, the future copies are pretty simple to check—the cp command doesn't run in the background, so one copy completes before the next one starts, so you don't need to check progress on the copy. Here's that version of the macro:

_Copy to folders.kmmacros (9.4 KB)

If you can start without the files on the clipboard, though, you can make it much smoother, as you can use the same cp command up front to make sure everything's copied before you start. This version of the macro does just that; you select the files to be copied in Finder first, then launch the macro. It runs a bit, then prompts you to pick the destination folders.

The other advantage is you don't have to open the temporary folder in order to paste into it, so it's all GUI-free. Overall, this is a very simple macro:

Macro screenshot

_Copy to folders - no clipboard.kmmacros (5.5 KB)

Neither of these methods are probably ideal for your needs, but they should give you some stuff to play with.


1 Like

I will check these tomorrow when my brain is a bit more relaxed...
I've been working on my own version, just as a challenge and so I can learn more about KM and I just can't seem to understand what's the issue here. Maybe you can see something I can't?

I am able to copy the original files once:

But then I get this error:
File action failed because source is not a full path %Variable%Local__fileToCopy%

===Copy selected files to selected folders Macro (v11.0.1)

===Copy selected files to selected folders.kmmacros (25 KB)

I'll have to look tomorrow as well as my brain is fried for the day :).