Versioning of Documents via an applescript

I’m looking to possibly create an applescript to do versioning of Adobe InDesign files. What I’d like it to do - is every X minutes while the system is running automatically copy the contents of one folder to a different folder. I would also like it to increment the filenames so that all of the versions are saved.

Is this even plausible?

If the folders are date_time stamped, is it really useful to date_stam the file themselves?

Yvan KOENIG (from FRANCE lundi 13 avril 2009 19:21:01)

Quick and dirty draft:


--[SCRIPT dateTimeStampedBackup.app]
(*
paste this script in the Script Editor

menu > File > Save As.
uncheck screen at startup
check stay in background
save this script as an Application Bundle

Install it as one of the applications launched at boot_time 
from the Accounts PreferencePane (tab Login Items)

Every ten minutes, the named folder will be duplicated in the Documents folder with the name "originalName_yyyymmdd-hhmmss". 

Yvan KOENIG (Vallauris, FRANCE)
13 avril 2009
*)

property minutesBetweenSaves : 10 (*
enregistrera toutes les 10 minutes *)
property folder2replicate : "the:path:to:the:folder:to replicate:"

--=====

on idle
	set p2d to path to documents folder
	set stamp to (do shell script "date " & quote & "+_%Y%m%d-%H%M%S" & quote)
	set curDate to current date
	tell application "Finder"
		set folderDate to modification date of folder folder2replicate
		if curDate - folderDate > 600 then
			set newCopy to duplicate folder folder2replicate to p2d
			set name of newCopy to (name of newCopy & stamp)
		end if
	end tell
	return minutesBetweenSaves * minutes
end idle

--=====
--[SCRIPT]

Yvan KOENIG (from FRANCE lundi 13 avril 2009 19:43:07)

Thanks Yvan, I think that’ll probably do what I’d like.

If it does what you need, I will search an alternate duplicate tool.
I’m quite sure that there is a more efficient one in the Shell but I’m not acustomed to this set of utilities.

Of course, in the posted script, you may add a few folders levels to fit your needs.

I used the Documents folder as a starting point (and as I am lazy).

Bingo, I found the Shell command and was able to apply it.



--[SCRIPT dateTimeStampedBackup.app]
(*
paste this script in the Script Editor

menu > File > Save As.
uncheck screen at startup
check stay in background
save this script as an Application Bundle

Install it as one of the applications launched at boot_time 
from the Accounts PreferencePane (tab Login Items)

Every ten minutes, the named folder will be duplicated in the Documents folder with the name "originalName_yyyymmdd-hhmmss". 

Yvan KOENIG (Vallauris, FRANCE)
13 avril 2009
*)

property minutesBetweenSaves : 10 (*
enregistrera toutes les 10 minutes *)
property folder2replicate : "the:path:to:the:folder:to replicate:"

--=====

on idle
	set p2d to path to documents folder
	set stamp to (do shell script "date " & quote & "+_%Y%m%d-%H%M%S" & quote)
	tell application "System Events" to tell disk item folder2replicate
		set sourceName to name
		set folderDate to modification date
	end tell
	if (current date) - folderDate > 600 then
		set source to quoted form of POSIX path of folder2replicate
		set dest to quoted form of POSIX path of (p2d as text) & sourceName & stamp
		do shell script "cp -R " & source & " " & dest
	end if
	return minutesBetweenSaves * minutes
end idle

--=====
--[SCRIPT]

Yvan KOENIG (from FRANCE lundi 13 avril 2009 22:40:50)