Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

The title should make it clear what I'm after but essentially I'd like a way to press command+some key to set up a ditto command for merging files and folders rather than obliterating and replacing them like command+C/command+V does.

How do you go about editing/viewing the keyboard commands and the terminal commands they map to?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You can do this by creating a Service using Automator that receives files and folders as input and is available in Finder. Add a Run Shell Script action that receives input as arguments and change the default script to a ditto call.

When you do it this way, you have no control over which directory is the src, and which is the target.


Alternatively, open Automator, create a Service that receives selected folders in Finder and add a Run AppleScript action 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

What this does: It will take your selection in Finder as source folders, prompt for a destination folder. and then execute

ditto src1 src2 src3 srcn dest

Save, and assign a keyboard shortcut in System Preferences » Keyboard » Keyboard Shortcuts » Services. Look for your service in the "Files and Folders" category and click to its right. Then you can press your desired shortcut.

share|improve this answer
    
Genius! Works great thanks –  sanchothefat Mar 5 '11 at 19:23
    
Out of interest is there a way to use what's in the copy buffer after command+C has been pressed? –  sanchothefat Mar 5 '11 at 19:41
    
@sanchothefat If you mean a file path copied in the Finder, use POSIX path of (the clipboard as «class furl») in AppleScript. This works only with a single path though. –  Daniel Beck Mar 5 '11 at 20:10
    
@Daniel-Beck I see. Thanks for the info and the code –  sanchothefat Mar 5 '11 at 20:20
    
@sanchothefat You can use it to replace the "Select Destination" dialog though. You would be able to "copy" the destination folder, select the source folders, and start the service. The order is somewhat reversed, but it might work for you. –  Daniel Beck Mar 5 '11 at 20:24
add comment

Your Answer

 
discard

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.