Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

futureswitcher

macrumors member
Original poster
Jan 12, 2008
80
0
Hey Everyone!
I ran into a situation last night where I wanted to sync two folders on my Mac, so I wrote an Applescript that I think does the trick (I haven't tested it out thoroughly, yet).
Here it is - I welcome any feedback or suggestions!

-futureswitcher

Code:
tell application "Finder"
	
	set projDate to modification date of folder "folder" of folder "Projects" of home
	set docDate to modification date of folder "folder" of folder "Documents" of home
	
	set difference to projDate - docDate (*if difference is positive, the projects folder is newer*)
	
end tell

if difference is less than 0 then
	display dialog "Syncing will overwrite changes to Projects.  Do you want to continue?" buttons {"Cancel", "Ok"}
	if button returned of result is "Ok" then
		do shell script "cp -R ~/Documents/folder ~/Projects/"
	end if
	
else if difference is greater than 0 then
	display dialog "Syncing will overright changes to Documents.  Do you want to continue?" buttons {"Cancel", "Ok"}
	if button returned of result is "Ok" then
		do shell script "cp -R ~/Projects/folder ~/Documents/"
	end if
end if
 
There are other ways to do this, you know... What does your script have over rsync or a program like Chronosync (well, I guess yours is free)?

Yeah, I don't really want to pay for anything. Also, I'm not familiar with rsync - I'll have to look into it.

In case there is anyone interested in this, I posted an updated version. I found out that the old script was only copying individual files so it didn't catch deletions:

Code:
tell application "Finder"
	
	set projDate to modification date of folder "folder" of folder "Projects" of home
	set docDate to modification date of folder "folder" of folder "Documents" of home
	
	set difference to projDate - docDate (*if difference is positive, the projects folder is newer*)
	
end tell

if difference is less than 0 then
	display dialog "Syncing will overwrite changes to Projects.  Do you want to continue?" buttons {"Cancel", "Ok"}
	if button returned of result is "Ok" then
                do shell script "rm -r ~/Projects/folder"
		do shell script "cp -r ~/Documents/folder ~/Projects/"
	end if
	
else if difference is greater than 0 then
	display dialog "Syncing will overwrite changes to Documents.  Do you want to continue?" buttons {"Cancel", "Ok"}
	if button returned of result is "Ok" then
                do shell script "rm -r ~/Documents/folder"
		do shell script "cp -r ~/Projects/folder ~/Documents/"
	end if
end if
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.