I get into this situation quite often but haven't found a solution. I have a group of CSS files in the clipboard that I need to paste + replace into several different destination folders. My folder structure is similar to

.
├── folderA_11
|   └── CSS
|        └── file1.css
|        └── file2.css
|        └── file3.css
├── folderB_11
|   └── CSS
|        └── file1.css
|        └── file2.css
|        └── file3.css
├── folderC_11
|   └── CSS
|        └── file1.css
|        └── file2.css
|        └── file3.css
├── folderD_22
|   └── CSS
|        └── file1.css
|        └── file2.css
|        └── file3.css
├── folderE_33
|   └── CSS
|        └── file1.css
|        └── file2.css
|        └── file3.css
└── folderF_44
    └── CSS
         └── file1.css
         └── file2.css
         └── file3.css
etc...

There's a pattern: I want to paste to all CSS folders whose container ends in _11 but not any of the others.

The content of the destination folders doesn't matter, I just need to replace them with the new files. Is there a simple way to paste these files into multiple destinations at once? It could also be an Automator flow or Terminal command.


As requested, here's a workable solution as we've discussed in the comments thread. Currently, the situation is that you have multiple files on the clipboard that need to be pasted into multiple destination folders. These destination folders are all called "CSS" and reside inside a set of parents folders (names ending "_11") that you are able to select en masse.

After doing that, you can run the following Automator service, either from the right-click context menu and selecting it under Services (or the Mojave equivalent); or by assigning it a keyboard shortcut in System Preferences, and triggering the service with the press of a hotkey.

The Automator service in question looks like this:

Automator service in macOS

The AppleScript code used in the Run AppleScript action is below. The AppleScript reads the list of files contained on the clipboard; isolates the "CSS" subfolders in each of the selected parent folders that were passed into the service (the "CSS" folder is created if it doesn't already exist); and then duplicates the files from the clipboard into the "CSS" directories.

If the clipboard does not contain any files, you'll hear a beep and no further action is taken.

use framework "AppKit"

property this : a reference to current application
property NSPasteboard : a reference to NSPasteboard of this
property NSURL : a reference to NSURL of this


on run {input, parameters}
    set pb to NSPasteboard's generalPasteboard()
    set fs to (pb's readObjectsForClasses:[NSURL] options:[]) as list

    using terms from scripting additions
        -- No files on clipboard, nothing to do
        if fs = {} then return beep
    end using terms from

    tell application "Finder" to repeat with f in the input
        set css to (a reference to the folder named "CSS" in folder f)
        if not (exists css) then make new folder at f with properties ¬
            {name:"CSS"}

        duplicate fs to css with replacing
    end repeat
end run

1 - Open Automator and create a new Service:

enter image description here


2 - Set the Service to receive Files and Folder in Finder:

enter image description here


3 - Drag an "Ask for Finder Items" action:

enter image description here


4 - Drag a "Run AppleScript" action:

enter image description here


5 - Paste this code:


on run {input}
    set numItems to count input
    set theFile to item (numItems) of input as text
    set numItems to numItems - 1
    repeat while numItems is not 0
        tell application "Finder"
            duplicate file theFile to folder (item (numItems) of input as text) with replacing
            set numItems to numItems - 1
            delay 0.1
        end tell
    end repeat
    display dialog "File copied to all folders" buttons {"Thanks"} giving up after 5
end run


6 - Save your workflow and name it as you want:

enter image description here


7 - USAGE: Select as many folders as you want, right click, services, find your workflow:

enter image description here

Select the file you want to copy (beware the window can be hidden behind the main one):

enter image description here

Click "Choose" and wait for the copy.

enter image description here

PS: the file will replace existing ones with the same name.