Personally, I did not like the idea of combining UNIX/POSIX scripts with AppleScript. To your point, . . . kind of messy. I implemented a similar algorithm as the AppleScript example in korn shell with the terminal app
#!/bin/ksh
today=`date '+%Y%m%d'`
delay=7
#
echo
echo Locate any data in the users' .trash directory or disk's .trashes directory. If previously scheduled to be removed, move it to a directory for mass removal. else schedule a date + 1 week it should be removed permanently.
echo
find /Volumes/*/.trashes/* /Volumes/*/.trashes/.[0-z]* /Users/*/.Trash/* -prune -exec ls -1d {} \; 2>/dev/null | grep -v trashInfo | grep -v deleteNow | while read trashFile
do
trashDir=`dirname "${trashFile}"`
base=`basename "${trashFile}"`
trashInfo="${trashDir}/.${base}.trashInfo"
echo -n "looking at ${trashFile}: "
du -sh "${trashFile}" | awk '{print $1}'
if [ -r "${trashInfo}" ]
then
dateToSRM=`awk '{print $NF}' "${trashInfo}"`
if [ $dateToSRM -lt $today ]
then
if [ ! -d "${trashDir}"/.deleteNow ]
then
mkdir -p "${trashDir}"/.deleteNow
fi
mv "${trashFile}" "${trashDir}/.deleteNow"
mv "${trashInfo}" "${trashDir}/.deleteNow"
fi
else
echo "date to secureRemove: " `date -v+${delay}d '+%Y%m%d'` > "${trashInfo}"
fi
done
echo
echo locate any trashinfo files without actual trash file and move it to the pending removal directory
echo
find /Volumes/*/.trashes/* /Volumes/*/.trashes/.[0-z]* /Users/*/.Trash/* -name '*.trashInfo' -prune -exec ls -1 {} \; 2>/dev/null | grep -v deleteNow | while read trashInfo
do
base=`basename "${trashInfo}" .trashInfo | sed s/^\.//`
trashDir=`dirname "${trashInfo}"`
if ! [ -r "${base}" ] > /dev/null 2>&1
then
mv "${trashInfo}" "${trashDir}/.deleteNow"
fi
done
echo
echo remove anything in the pending removal directory
echo
du -sk /Volumes/*/.trashes/.deleteNow/* /Users/*/.Trash/.deleteNow/* | sort -nr | uniq| while read size realTrash
do
echo -n "looking at ${realTrash}: "
du -sh "${realTrash}" | awk '{print $1}'
chmod -R 777 "${realTrash}"
srm -rfmz "${realTrash}" 2>/dev/null &
done
numFiles=`find /Volumes/*/.trashes/.deleteNow/* /Users/*/.Trash/.deleteNow/* -prune -exec ls -1d {} \; 2>/dev/null | wc -l`
while [ $numFiles -gt 0 ]
do
echo
echo
du -sk /Volumes/*/.trashes/.deleteNow/* /Users/*/.Trash/.deleteNow/* 2>&1 | grep -v "No such file" | sort -nr | head -5 | awk '{printf "%2.2f MB %s\n",$1/1024,$2}'
sleep 60
numFiles=`find /Volumes/*/.trashes/.deleteNow/* /Users/*/.Trash/.deleteNow/* -prune -exec ls -1d {} \; 2>/dev/null | wc -l`
done