Hi! I’m new to this forum and still new at Applescript.
I’m administering a college computer lab, and it’s time to do some drive cleaning between semesters. I found a script to delete files off the desktop without much trouble, but deleting files saved elsewhere throughout the hard drive seems to be harder to script. (This script will be used with Apple Remote Desktop.)
Is there a way to search for all the files created by a certain user (for example, all our machines have a “student” account) and then delete them? I’ve done some searching, but so far I’ve only found how to delete files created within a certain timeframe, like this:
try
set myFolder to (choose folder)
set myTime to display dialog "Delete files older than how many days?" default answer "60"
set myWildcard to display dialog "Enter a wildcard search string." default answer "PV*.txt"
set myScript to "find \"" & POSIX path of myFolder & "\" -type f -name \"" & text returned of myWildcard & "\" -mtime +" & text returned of myTime & " -exec rm {} \\;"
do shell script myScript
display dialog "Deletion completed successfully"
on error err
display dialog err
end try
I’m worried the above script might delete updated applications.
I’ve also found this script, “How can I move files in Folder A to the trash, except for Folder B?” from the OS X Finder section:
property doNotDelete : {alias "Macintosh HD:Folder B:", alias "Macintosh HD:Folder C:", alias "Macintosh HD:Folder D:"}
tell application "Finder"
move every item of doNotDelete to desktop -- Moves Folders B, C and D to the Desktop
move every item of alias "Macintosh HD:Folder A:" to trash -- Moves everything else in Folder A to Trash
move every item of doNotDelete to alias "Macintosh HD:Folder A:" -- Moves Folders B, C and D back to their original location (Folder A)
end tell
I’m worried that script might require me to name every folder I want to search… but I want to search the entire hard drive.
Would some combination of the two scripts above work?
I’ve also thought about writing a script that would delete certain types of files - but our students use lots of software and create a wide variety of file types.
Over the summer we’ll reload all the machines with a new drive image, but I’m hoping to come up with a less intense script to run before classes start again on January 24th.