Empty the Trash every Sunday at set time

hi everyone.

I am still a newbie at applescripting, and thanks to the people on this site, have created my first successful script. Now I am faced with phase 2 of this script. basically, what I want to do every sunday at about 1am is to empty the trash. The emptying of the trash can be done by a applescript, but where i am stuck is how do i get this script to only run on a sunday, is there a way i could make it run at startup, and then somehow it waits to be run, or could i use a unix cron tab to make this run?

Any help will be greatfully appreciated. :smiley:

There is nothing built-in to AppleScript that will schedule a task like this.

You either need a third party app (like ‘Script Scheduler’ whose ad appears on virtually every page in these boards - just look up), or you can use cron.

If you want the cron approach, the actual command you use will vary depending on whether you save the script as an application or as a compiled script. I’d recommend compiled script, but it’s your call. In either case you’d edit your crontab (crontab -e) and set one of:

0 1 * * 0 osascript /path/to/your.scpt
0 1 * * 0 /path/to/your/script.app

Note, though, that this can be dangerous!

I’m guessing that you’re emptying the trash by telling application “Finder” to do something, right?

The script will fail if the Finder is not running at the time cron fires off. The Finder might not be running if you’ve logged out of your machine, or if another user is logged in. Therefore a simpler (non-AppleScript), safer approach may be:

0 1 * * 0 /bin/rm ~/.Trash/*

Unfortunately it doesn’t use AppleScript, but it also doesn’t need any additional apps to do its thing.

Or, you can schedule the script to run according to your schedule using iCal.

The version of iCal after 1.5.1 (I think…) treats scripts as events and so you can make it activate the script according to your schedule.

You may want to check Apple’s website, especially on iCal, for examples on how to automate repetitive tasks using iCal.

Good luck :idea:

thanks to both of your replies. I will try both ways and see which will best suit the environment I want to run this in.

Have a great christmas, and thank you for your time and your kind assistance. :smiley: