I’ve written a logout hook (with assistance from StefanK) that was successful, but recently found after a little beta testing that the script ends prematurely (while emptying the trash) without waiting for all processes to complete. After making some adjustments I’ve discovered how to make the script wait but it ends up crashing Finder (which also kills the logout process).
This is what I have thus far (which does not wait for completion of “empty trash” and suppresses any error windows that Finder flags when trying to logout and clearing the trash bin simultaneously):
tell app “Finder”
move (items of the desktop whose kind is not “Volume”) to trash
do shell script “du -ks /Users/student/.Trash”
if (first word of(do shell script “du -ks /Users/student/.Trash”)as number) > 50000 then empty trash
delay 2
if (first word of(do shell script “du -ks /Users/student/.Trash”)as number) < 150 then repeat
end repeat
try
on error
tell app “Trasher App” to close (first window whose frontmost is true) in window 1
end try
end tell
end if
So should I have System Events keeping track of the “Trash” window process?? If so how do I prevent this (or any other modification to the script) from interfering with the logout process in a logout hook??!