How can I make a keyboard shortcut for the ditto command in OSX Finder?

0

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?

sanchothefat

Posted 2011-03-04T23:04:55.533

Reputation: 118

Answers

2

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.

Daniel Beck

Posted 2011-03-04T23:04:55.533

Reputation: 98 421

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

0

With one adjustment to the aforementioned Applescript, namely

"ditto -x -k "

You can modify this to be a service for Finder to unzip (extract) one or multiple .zip files to your chosen directory with one click.

Sparrow1029

Posted 2011-03-04T23:04:55.533

Reputation: 1