Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to make an Automator action that copies a set of files from a folder to another folder that is one folder up and then two folders down from the original files. In other words: ../Folder1/Folder2. The Automator action would be in the same folder as the files, but the root folder will be duplicated and renamed across multiple computers, so the path MUST be relative.

My understanding is that I need to run an Applescript to grab the current path and then do...something. I have zero scripting experience. Can anyone help?

enter image description here

share|improve this question
I know the shell can be intimidating, but while this can be done in Automator, it is so easy in the shell that you might want to start getting comfortable with it: cp files*.txt ../Folder1/Folder2 – beroe Sep 10 '13 at 20:56
Forget my dumb question The Action IS an Application :-) – markhunte Sep 10 '13 at 21:39
Have added two more versions to my answer.. – markhunte Sep 11 '13 at 17:47
up vote 1 down vote accepted

Instead of AppleScript, you could do it by adding a Run Shell Script module with this content:

for F in "$@"; do
    cp "$F" "${F%/*/*}/Folder1/Folder2/${F##*/}"

Edit the names of Folder1/Folder2 to match your actual case.

Choose As arguments from the Pass Input: pop-up at right where it says to stdin.

$@ stores the full path of all files selected. $F is each individual file's path as it is processed by the for loop. The weird ${F%/*/*} is the full path of the file minus the file name and its parent folder name. The weird ${F##*/} is the file name itself.

Test first for safety!

Image of script

The other way to do it, which I think would be easier in the long run:

  1. Open a terminal window.
  2. Type cdspace and drag the folder containing your files into the window. (This will paste in the path to that folder. Be sure to include the space after cd before you drag-and-drop.)
  3. Type cp *Video* ../Folder1/Folder2
  4. Done!
share|improve this answer
So, your other answer: cp files*.txt ../Folder1/Folder2 is simpler and better? This answer with the for-loop is more general, in that it doesn't assume the particular extension of ".txt"? – Kaydell Sep 10 '13 at 21:47
Well, the command that you type each time you need it is the most flexible, moreso than the for-loop. I just put *.txt as an example of a way to select multiple files. That could be anything. If you go the Automator route, then you have the step of using the GUI to select files (may be easier or harder depending on the context), but it is definitely harder to change the Folder1/Folder2 destination by editing the Automator script each time you want to use it. – beroe Sep 10 '13 at 21:52
I am staring at your shell script, and I really have no idea what to do with it. Hand holding would be greatly appreciated:… – Ben Dansby Sep 11 '13 at 16:09
I edited the answer. I had neglected to mention that the as arguments option needed to be selected. Also added the native shell command, if you want to get adventurous. – beroe Sep 11 '13 at 17:40
I got it all working with multiple instances of each step to copy different sets of images. Thanks so much for your help! I'd upvote you if I had the karma :-) – Ben Dansby Sep 12 '13 at 16:19

UPDATE* trimmed down the code a little bit, and corrected the path

Since you asked for applescript…

on run {input, parameters}
    tell application "Finder"
        set thefolderPath to "folder1:folder2:"
        set mycontainer to (path to me)
            set movePath to folder thefolderPath of container of (path to me)'s container as alias
        duplicate input to movePath

    end tell

end run

This also does away with the copy action since the duplication is done here also.


With this version. It does not matter where the App is. The path is worked out by where the files are.

on run {input, parameters}
    set thefolderPath to "folder1:folder2:"
    tell application "Finder"
        set thisItem to item 1 of input as alias
         set movePath to folder thefolderPath of container of (thisItem)'s container as alias
        duplicate input to movePath

    end tell

end run


This version is the same as update 2. But will test for your folder1 and folder2.

If either folder does not exist it will make them and move the files to them. If only folder2 does not exist. Then it will only make that folder inside folder1. Meaning existing items in folder1 are safe.

on run {input, parameters}
    set thefolderPath to "folder1/folder2/"
    tell application "Finder"
        set thisItem to item 1 of input as alias
        set movePath to container of (thisItem)'s container as alias
        set theTestPath to ((POSIX path of movePath) & "/" & thefolderPath)

        if (do shell script "/bin/test -e " & quoted form of theTestPath & " ; echo $?") is "1" then
            -- 1 is false
            do shell script "/bin/mkdir -p " & quoted form of theTestPath

        end if
        set theActualPath to (POSIX file theTestPath) as alias
        duplicate input to theActualPath

    end tell

end run
share|improve this answer
Thanks for the script! Unfortunately, it only works when I run it from Automator, so the files get deposited within the Applications folder (after I set up the proper folder structure within Applications). When I try and run it from the Finder (even when it's within the Applications folder), I get a dialog box telling me there was an Applescript error. – Ben Dansby Sep 11 '13 at 15:40
Here is a video demonstrating: – Ben Dansby Sep 11 '13 at 15:49
AH I have updated it. I did not relies you had the app in 'Folder' – markhunte Sep 11 '13 at 17:05
By the way how is this used and why. Just thought it is an odd way to hard code an app to copy some files. – markhunte Sep 11 '13 at 17:07
Hi Mark, thanks so much for working on this. Beroe's answer above worked for me, but I'm going to study your answer as I imagine it could be helpful in other situations. The way I'm using this is to take a whole bunch of images, each of which have one or more "tags" in their file names, and triage them to different folders based on their tags. The whole thing needs to be portable because it will end up getting duplicated, renamed, and moved to many different computers. – Ben Dansby Sep 12 '13 at 16:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.