|
|
#1 |
|
Prospect
Join Date: Jul 2004
Posts: 5
|
Applescript needed - Delete files older than 3 days
For a lab OS-X machine, I need to write an Applescript to run at startup which will delete all files from a "User Data" partition (including any subdirectories) which are older than 3 days.
Anyone help me out? |
|
|
|
|
|
#2 |
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
|
This is something that is probably better done in a shell script instead of AppleScript. You would use the 'find' program in a shell script.
See for example, this thread: http://forums.macosxhints.com/showthread.php?t=6774 |
|
|
|
|
|
#3 |
|
Hall of Famer
Join Date: Jan 2002
Posts: 3,016
|
Do you happen to be managing this lab with OS X Server? Doesn't it allow automatically restoring hard drive images? This might be the easiest way.
Chris |
|
|
|
|
|
#4 | |||||||||||||||||||||||
|
Prospect
Join Date: Jul 2004
Posts: 5
|
No, using Windows 2000 server at the moment |
|||||||||||||||||||||||
|
|
|
|
|
#5 | |||||||||||||||||||||||
|
MVP
Join Date: Apr 2004
Location: Cumbria, UK
Posts: 2,461
|
If you must run the script at startup then you're sunk as you must be logged in before any Applescripts can be run. If it must be at startup then you will have to use a shell script. |
|||||||||||||||||||||||
|
|
|
|
|
#6 | |||||||||||||||||||||||
|
Prospect
Join Date: Jul 2004
Posts: 5
|
well how about as a login event when I login as a speficic user? the machines all auto-login to one user account and I already run a script on login to mount a network volume..... Last edited by murpheeee; 07-20-2004 at 02:23 PM. |
|||||||||||||||||||||||
|
|
|
|
|
#7 |
|
Triple-A Player
Join Date: Jul 2003
Posts: 55
|
I need the same
Well I have the same problem. I have this script that worked under Jaguar but not under Panther
maybe someone can help us or finish it for us ![]() tell application "Finder" set FOLDERwithITEMS to alias ((startup disk as string) & ":Users:testuser ocuments")if (count of FOLDERwithITEMS) < 1 then empty else set locked of (files of entire contents of FOLDERwithITEMS) to false update (files of entire contents of FOLDERwithITEMS) delete entire contents of FOLDERwithITEMS empty end if end tell |
|
|
|
|
|
#8 |
|
Prospect
Join Date: Jul 2004
Location: San Francisco Bay Area
Posts: 3
|
Lab Environment Scripts
I saw a presentation on managing labs using Mac OS X. They had an excellent presentation and some useful scripts
http://www.macosxlabs.org/tools_and_scripts/index.html |
|
|
|
|
|
#9 |
|
Prospect
Join Date: Jul 2004
Posts: 5
|
I was told on another board to add this to the RC file:
#BEGIN echo -n "Removing contents of UserData..." find /Volumes/UserData ! -atime 3 -exec rm {} \; echo "Done" # END Which I did....but it does not seem to do anything..... |
|
|
|
|
|
#10 |
|
MVP
Join Date: Apr 2004
Location: Cumbria, UK
Posts: 2,461
|
Here's a Applescript/shell script that does what you want. You need to change the property "root_folder" to be the UNIX path of the top level folder.
Code:
property root_folder : "full UNIX path to the top level folder" set thescripttext to "find " & root_folder & " -type d -mtime +3 -print0 | xargs -0 rm -R" do shell script thescripttext set thescripttext to "find " & root_folder & " -type f -mtime +3 -print0 | xargs -0 rm" do shell script thescripttext |
|
|
|
|
|
#11 |
|
Prospect
Join Date: Feb 2006
Posts: 2
|
I needed a solution for this type of thing too.
In my case I have a backup folder filling up with one 35 mb file per day. I want to keep the latest two files. I found an Apple Script at another forum and added the code that checks for new items. Apply this to a folder as a folder script and the folder will keep itself clean. Increase the number 2 to to keep even older files. Code:
on adding folder items to this_folder after receiving added_items try tell application "Finder" try delete (every item of folder "myfoldername" of folder "Desktop" of folder "myusername" of folder "Users" of startup disk whose modification date is less than ((get current date) - 2 * days)) end try end tell end try end adding folder items to |
|
|
|
|
|
#12 |
|
Prospect
Join Date: Feb 2002
Location: Brisbane / Australia
Posts: 33
|
Hi there,
just browsing the forums and came acros this post. A while ago I wrote a shell script designed to be run as a cron/launchd job (in a lab environment) to clean files that have not been created/edited/viewed for more than a specified period of time. Feel welcome to use it if it suits your needs, it has been tested quite a bit but of course it's provided "as-is" and if you use it to break something (it can be VERY destructive when used without caution) don't come crying back to me. Regards, Trystan |
|
|
|
![]() |
|
|