Synchronize Folders - A Script
Synchronize Folders - A Script
- Subject: Synchronize Folders - A Script
- From: "Stephen Swift (aka Burnum)" <email@hidden>
- Date: Sat, 16 Jun 2001 16:24:15 -0400
Someone here wanted a script that would monitor a folder and then update the
contents of another folder. Here is a script I designed to do this.
However, you'll have to refine it for your own purpose. I'm not sure what
happens when you have an empty folder or the folder you copy to is on an
unmounted server.
Note: Beware of E-mail wrapping.
property TimeToSleep : 1 -- How many minutes until we check again
property FolderToWatch : "" --must be initialized
property theContents : {} -- contents of folder
property modDate : date "Friday, January 1, 1904 12:00:00 AM" --
modification date of folder when last we checked
property FolderToCopyTo : ""
on run
tell application "Finder"
if FolderToWatch = "" then
try
set NewFolder to choose folder with prompt "Select the
folder you want to monitor:"
on error -- e.g. user canceled
end try
set FolderToWatch to NewFolder
set theContents to list folder FolderToWatch
set modDate to modification date of FolderToWatch
end if
if FolderToCopyTo = "" then
try
set FolderToCopyTo to choose folder with prompt "Select the
folder you to copy to:"
on error -- e.g. user canceled
end try
end if
end tell
idle
end run
on idle
tell application "Finder"
set newModDate to modification date of FolderToWatch
if newModDate > modDate then
set NewContents to list folder FolderToWatch
repeat with x in NewContents
if x is not in theContents then
duplicate alias ((FolderToWatch as text) & x) to
FolderToCopyTo
end if
end repeat
end if
end tell
return TimeToSleep * 60 -- Sleep time * seconds in a minute
end idle
Stephen Swift ?' The Burnum Man
email@hidden
-----------------------------------------------
"He was the only person I met who knew more about electronics than me." -An
exaggeration by Steve Jobs, explaining his initial fascination with Woz