Use AppleScript to Automatically Empty the Network Trash Folder

By: Richard Glaser - Revised: 2006-06-22 devin

Section Links

  1. Overview
  2. Setup


To setup AppleScript automatically emptying the "Network Trash Folder" I used the following software...

AppleScript - to download the latest version, click here. (link dead)

iDo Script Scheduler is software that allows scheduling the running of AppleScripts. You set up schedules by creating "events", which can run scripts one time, or at any repeating interval from minutes to weeks, when a "hot-key" is pressed, and when the system is idle.

Jon's Commands is a Scripting Addition that is used to delete "Network Trash Folder" contents. It also provides added functionality in the form of about 30 useful commands which can be called from AppleScript.

Appearance OSAX (link dead) is a Scripting Addition that is used to provide user feedback. With Appearance OSAX you can display enhanced movable alerts, post system notifications, and create floating windows with text messages and progress indicators.


(1) If you do not have AppleScript installed on your ASIP file server, install it.

To check if you have it installed, you should have the following items in your System Folder...
  • Scripting Additions folder - Located in root of the System Folder
  • AppleScript - Located in the "System Folder:Extensions" folder
  • AppleScriptLib - Located in the "System Folder:Extensions" folder
(2) Install iDo Script Scheduler, the lite versions comes with Mac OS 9.x. Or you can upgrade to the "Enhanced" version for additional "events" when a "hot-key" is pressed, and when the system is idle.

It will install the following items on the server...
  • iDo Script Scheduler - Located in the System Folder:Control Panels" folder.
  • iDo Script Scheduler Extension - Located in the "System Folder:Extensions" folder.
  • iDo Folder - Located in the "System Folder:Preferences" folder.
(3) Install Jon's Commands, by dragging the scripting addition to the "System Folder:Scripting Additions" folder.

(4) To provide user feedback whilst the AppleScript is running, install Appearance OSAX.

NOTE: When the AppleScript is processing, you will get 5 to 10 second pause in mouse movement, etc., which might appear to users that the server is hung, hence the user feedback.

To install "Appearance OSAX" drag scripting additions to the "System Folder:Scripting Additions" folder.

(5) Next you need to modify, test, and debug AppleScript to fit your current sharepoint setup.

This is the generic AppleScript:

(6) Modify AppleScript to match your servers sharepoint(s) path(s)...

On the lines:

set Share_Point_Path1 to "Hard Disk:Share Point1"
set Share_Point_Path2 to "Hard Disk:Share Point2"
set Share_Point_Path3 to "Hard Disk:Share Point3"

Change the text "Hard Disk:Share Point1", "Hard Disk:Share Point2", and "Hard Disk:Share Point3" to match your server sharepoint(s) paths.

Fewer Sharepoints
If you have fewer sharepoints, delete the corresponding lines (i.e. "Hard Disk:Share Point2", "Hard Disk:Share Point3", etc.) .

More Sharepoints
If you have more sharepoints, add the corresponding lines (i.e. "Hard Disk:Share Point4", "Hard Disk:Share Point5", etc.)

(7) If you have added or deleted lines above, modify the following lines...

On the lines:

set Network_Trash_Folder_Path1 to Share_Point_Path1 & ":Network Trash Folder" as alias
set Network_Trash_Folder_Path2 to Share_Point_Path2 & ":Network Trash Folder" as alias
set Network_Trash_Folder_Path3 to Share_Point_Path3 & ":Network Trash Folder" as alias

Add or remove lines depending on the modifications you made to the sharepoint paths above. The reason for these lines, is to put minimal safeguard for user mistakes, typo's, etc.

(8) If you have added or deleted lines above, modify the following line...

set The_Network_Folders to {Network_Trash_Folder_Path1, Network_Trash_Folder_Path2, Network_Trash_Folder_Path3}

Fewer Sharepoints
If you have fewer sharepoints, delete the variables (i.e. "Network_Trash_Folder_Path3", "Network_Trash_Folder_Path2", etc.) .

More Sharepoints
If you have more sharepoints, add the corresponding variables (i.e. "Network_Trash_Folder_Path4", "Network_Trash_Folder_Path5", etc.)

(9) Test & Debug

WARNING: If you have mistakes, or typo's you can delete items from folders that you do not intend. Make sure you double-check (and triple-check) that your paths are correct. Also, you might test the script first on non-production box. Basically, simulate the paths to sharepoints on your server, by creating similar folder structure. Since the name "Network Trash Folder" is reserved by the Mac OS, name your test folder (and the path in the script) to something else like "Network Trash Folder Ä".

Then add items inside this "test" folder and run the script.

Also, to be really cautious, make sure you have a recent backup of your file server before trying it on the server.

(10) Once you have tested and debugged the AppleScript, in Script Editor save it as a "Classic Applet", and set the "Never Show Startup Screen" option.

Then copy the applet to your file server in any desired folder.

(11) Now, you can setup the schedule to launch the AppleScript applet. Open the "iDo Script Scheduler" control panel.

Unless you have previously added events, the window will be empty. Click on the "New..." button.

Select the desired "Trigger" (i.e. Repeating, Days of Week, Day of Month, etc.) and set desired options, then select your "Empty Network Trash Folder" applet.

I would recommend a time/date that your server is under less load and good availability of the administrator to troubleshoot issues.

After you have setup iDo Script Scheduler to automatically run your applet. I would recommend manually checking the "Network Trash Folder" folders, to make sure everything is working properly after the time/date it is supposed to launch it.

If all is working properly, you are done.