Hi all,
I would like to know if it's possible to make an applescript that checks every day a folder on desktop that contains files and folders (in particular folders with a name and a date like "Builds 20 nov 2012", "builds 21 nov 2012" etc etc with files inside) and copy the files inside last folder named "builds 21 nov 2012" (as for today, tomorrow would be "builds 22 nov 2012") depending on the date to a Folder named "last builds" on a nas server that is connected and mounted on desktop, deleting the old files on it, leaving only the last ones.
If it is possible any help would be appreciated!
Thanks,
Al
Let's see if I understood correctly what you want.
1. You have a folder in Desktop called -let's say- A/.
2. You then have:
A/21.11.2012/
A/20.11.2012/
A/19.11.2012/
[…] (more older folders)
3. You want the script to copy the files in A/21.11.2012/ (last folder) to a folder in a NAS drive, let's call it /Volumes/NAS/LastFiles/.
Correct?
There's probably a better way but this is what I'd do. Just create a script with the following commands:
Code:
y=`date '+%Y'`
m=`date '+%m'`
d=`date '+%d'`
f=$d.$m.$y #today's folder's name
rsync -aEP --delete /Desktop/A/$f/ /Volumes/NAS/LastFiles/
This will delete everything in /Volumes/NAS/LastFiles/ except those files also present in /Desktop/A/21.11.2012/ (assuming that's the last folder) and copy new files present in /Desktop/A/21.11.2012/.
I have a couple of these scripts for my own use. I ran them every time I want them to make a backup, in case you wanna just run the script and let it do by itself, I'd add the following to the code.
Code:
while [ 1 ]
do
y=`date '+%Y'`
m=`date '+%m'`
d=`date '+%d'`
f=$d.$m.$y #today's folder's name
rsync -aEP --delete /Desktop/A/$f/ /Volumes/NAS/LastFiles/
sleep 5184000 #this will put the script to sleep for 24h
done
I'm pretty sure this'll work. I'm also sure there's a more elegant way to do it but this is the structure I use for my own.
Note that -in this second scenario- everytime you reboot your computer you'll need to execute the script again.
Cheers.
P.S: Please someone correct me if there's a mistake in the code or, as I stated, a better way to do it, as I'll be interested myself!
------------------------------
Added:
If you go the second way, this is what will happen:
1. You run the script on 22.11.2012 at 15.00.
2. It'll sync the folder Desktop/A/22.11.2012/ with /Volumes/NAS/LastFiles/
(Let's assume this takes 24 minutes)
3. Go to sleep for 24h.
4. At 15.24 on the next day, it'll sync the folder Desktop/A/23.11.2012/ with /Volumes/NAS/LastFiles/.
5…
6…
This means that on your NAS/LastFiles folder you'll just have the files in your most recent folder in Desktop/A/. I think this is what you wanted, right?