|Nov 21, 2012, 02:21 PM||#1|
Little question on Applescript
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!
|Nov 21, 2012, 04:32 PM||#2|
1. You have a folder in Desktop called -let's say- A/.
2. You then have:
[…] (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/.
There's probably a better way but this is what I'd do. Just create a script with the following commands:
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/
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.
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
Note that -in this second scenario- everytime you reboot your computer you'll need to execute the script again.
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!
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/.
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?
2012 Mac Mini
|Nov 21, 2012, 05:27 PM||#3|
I would use launchd to run the script every day. Also a folder named 21.11.2012 isn't the same as particular folders with a name and a date like "Builds 20 nov 2012", "builds 21 nov 2012" etc etc.
Info : Timed Jobs Using launchd and Running a Job Periodically
Space Corps Directive 34124
|Nov 22, 2012, 05:24 PM||#4|
As for the folder's name… Doesn't really matter as that can also be printed out…
day=`date '+%d'` month=`date '+%b'` year=`date '+%Y'` echo "Builds $day $month $year"
Mini:~ User$ day=`date '+%d'`; month=`date '+%b'`; year=`date '+%Y'`; echo "Builds $day $month $year" Builds 23 nov 2012 Mini:~ User$
2012 Mac Mini
|Thread Tools||Search this Thread|
All times are GMT -5. The time now is 05:08 AM.