Skip to content

Instantly share code, notes, and snippets.

@ryjen
Created March 7, 2012 19:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryjen/1995482 to your computer and use it in GitHub Desktop.
Save ryjen/1995482 to your computer and use it in GitHub Desktop.
Merge Folders AppleScript

Installation

  • Run Automator
  • Select Service as the new document type
  • Find Run AppleScript from the Library and drag into the workflow
  • Copy the script code into the Run AppleScript action
  • Save as Merge Folders

Optional

  • Open System Preferences -> Keyboard -> Shortcuts
  • Add key combination for merge folders service

Usage

  • Select a folder
  • From (context) menu select Services -> Merge Folders
--- Merge Folders v1
--- Author: c0der78@gmail.com
--- handler for performing the merging.
on merge(src_paths, dest_path)
--- Uses the 'ditto' shell command as a backend
set cmd to "ditto " & src_paths & quoted form of dest_path
try
do shell script cmd
on error
--- Retry with admin privileges on error
do shell script cmd with administrator privileges
end try
end merge
on run {input, parameters}
set dest to choose folder with prompt "Select destination for merge:"
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
try
merge(src_paths, dest_path)
on error msg
display dialog the msg
end try
end run
@kevinSuttle
Copy link

Unfortunately doesn't seem to work on Mavericks. :/

@dcnetw0rk
Copy link

dcnetw0rk commented Jan 20, 2023

I made some edits and this will work in Automator as a Quick Action:

on run {}

tell application "Finder"
	set src_folder to get the selection as text
end tell

set src_folder to quoted form of (POSIX path of src_folder)
log "Source Fldr: " & src_folder

set dest to choose folder with prompt "Select destination for merge:"
set dest_folder to dest as text

set dest_folder to quoted form of (POSIX path of dest_folder)
log "Destination: " & dest_folder

set rootpw to "rootpw=$(cat ~/.pw_vault.txt | openssl enc <all the options> pass:'vaultpw')"
set cmd to "echo $rootpw | ditto -V " & src_folder & " " & dest_folder

do shell script rootpw

try
	do shell script cmd
on error
	do shell script cmd with administrator privileges
end try

log "Merge complete!"
log "Source Fldr: " & src_folder
log "Destination: " & dest_folder

end run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment