I am totally new to AppleScript and I am trying to learn it by solving a real problem.
I use OmniFocus on my iMac as my task management tool. OF generates a lot of backup-files that fill a certain folder. This folder grows bigger and bigger.
I wish to monitor the backup-folder and delete the oldest files if the backup-folder-size exceeds a certain size (just like TimeMachine does with the oldest files when the hard drive is full).
Before I have even thought about AppleScript I have imagined something like this:
repeat until backup-folder-size < maximum-size delete oldest file in the backup-folder end-repeat
I have tried this with Hazel, but Hazel doesn’t run loops, so I thought I could make an AppleScript for the loop and put this AppleScript in a Hazel-rule.
So I have started to learn AppleScript! I have made a script that asks for the backup-folder and the wish maximum-size and even displays the folder size and the number of the files within this folders.
Right now I would like to
a) Save the file name, the file size and the creation-date of each file in the backup-folder in an internal table; b) Then sort this table by creation-date; c) Sum the file-sizes of the files in the sorted table until the wish maximum-size is reached; d) Save the index of the table-element, where this happens; e) And finally move all the remaining files into a "to_be_deleted"-folder.
1.- Does something like a table / array exist in AppleScript (for a) above)? Assuming that an AppleScript list is the same as a 1-dimensional table, than a more-dimensional-table should be something like. a list of lists?! Hmmm…
2.- How does one address / load the sizes, creation-dates and the name of each file in the chosen folder in the table-elements? 3.- How does one sort this table?
Thank you for your patience and suggestions!
Model: iMac 3.06 GHz Intel Core 2 Duo
Browser: Safari 533.21.1
Operating System: Mac OS X (10.6)