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?
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:
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.