Use Applescript to copy files from a shared folder with ease and without duplicates
February 10th, 2011
Recently I’ve begun to share a folder on Dropbox with some friends in which the contents are constantly changing without notice. The problem that arose for me when I viewed the shared folder is that I often couldn’t remember which files I’d already snatched up and which one’s I had not. I initially did the logical thing which was to go my local folder and compare it’s contents against the contents of the shared folder. But as the contents changed more quickly, the task became just too tedious. As a result, I made this simple Applescript as a time saver – Enjoy.
tell application "Finder"
#change the text between double quotes to the folder for which you want
#your new files copied FROM
#ex. "Macintosh HD:Users:your_name_here:your_folder_here"
set srcLocation to "Macintosh HD:Users:jbattle:dropbox:music:"
set list_all_srcFiles to name of every file of folder srcLocation
set list_all_srcFolders to name of every folder of folder srcLocation
#change the text between double quotes to the folder for which you want
#your new files copied TO
#ex. "Macintosh HD:Users:your_name_here:your_folder_here"
set destLocation to "Macintosh HD:Users:jbattle:music:iTunes:iTunes Music:"
set list_all_destFiles to name of every file of folder destLocation
set list_all_destFolders to name of every folder of folder destLocation
repeat with current_file in list_all_srcFiles
if list_all_destFiles contains current_file then
#do nothing
else
tell application "Finder" to duplicate srcLocation & current_file to folder destLocation
end if
end repeat
repeat with current_folder in list_all_srcFolders
if list_all_destFolders contains current_folder then
#do nothing
else
tell application "Finder" to duplicate srcLocation & current_folder to folder destLocation
end if
end repeat
say "Your local copy is current"
end tell
Instructions for installation and configuration:
- Download the script to a location on your computer you can remember
- Open the script file
- Modify the line that reads “set destLocation…” per the comments in the code
- Modify the line that reads “set srcLocation…” per the comments in the code
- Click File > Save
- Close the script
- Move the script to the ~/Library/Scripts
You’re done. To run your script, select the script from the script menu bar icon and you haven’t wasted any time.
Note: For this script to work, folders for the srcLocation
and destLocation
must exist.