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.
Out of interest is there a way to use what's in the copy buffer after command+C has been pressed? – sanchothefat – 2011-03-05T19:41:20.113
@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 – 2011-03-05T20:10:15.797@Daniel-Beck I see. Thanks for the info and the code – sanchothefat – 2011-03-05T20:20:32.203
@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 – 2011-03-05T20:24:40.030