How to use Automator to give a GUI to ditto?

1

2

How do I create an Automator workflow, service or folder action to use ditto. The intention here is to use ditto to merge folders and/or files avoiding the unacceptable Finder's behavior of replacing the folder/file by the new one.

msmafra

Posted 2011-03-22T03:15:30.437

Reputation: 231

Answers

1

Create a Service that receives folders in Finder. Add a single Run AppleScript action to it with the following script code:

on run {input, parameters}
    set dest to choose folder with prompt "Select destination:"
    set dest_path to (POSIX path of dest) as text
    set src_paths to ""
    repeat with idx from 1 to count (input)
        set src_paths to src_paths & (quoted form of (POSIX path of item idx of input as text)) & " "
    end repeat
    set cmd to "ditto " & src_paths & quoted form of dest_path
    do shell script cmd
end run

The script will execute

ditto selectedFolder1 selectedFolder2 selectedFolderN folderChosenInDialog

Assign a keyboard shortcut for convenient access in System Preferences » Keyboard » Keyboard Shortcuts » Services.

Daniel Beck

Posted 2011-03-22T03:15:30.437

Reputation: 98 421

It works but not in the way I want. But it's my fault. I want to copy a folder named "my files" from a flash drive to a folder also named "my files" in my Documents folder (for example) what it should do is update the files not delete all the content and replace with the new one as is the default behavior. Like in Linux or even Windows. – msmafra – 2011-03-24T16:42:18.517

@tenshimsm Cannot reproduce. It doesn't clear destination for me. I gave you the command that is executed in my post, and you specifically requested use of ditto. If you want to add parameters to change ditto's behavior, it's trivial to edit the third to last line. – Daniel Beck – 2011-03-24T17:51:14.947

@tenshimsm Screenshot when I tested it. Clearly 1 is destination, and c existed only there, before performing the command.

– Daniel Beck – 2011-03-24T20:03:34.447

Your code is very useful for me. I try it and see if it is my "lameness". :) – msmafra – 2011-03-25T20:05:01.397