Help with Scripts...

: Version one is a non-timed script and is designed to
: empty the bin every time the
: computer is shut down.
: Version two of the script is a slightly more
: sophisticated version that is designed to
: get rid of the items in the bin that are more than 24hrs
: old.
: Version one runs perfectly on our iMacs, but when run on
: our G3 comes up with the
: error message “The variable Wastebasket is not
: defined”. (BB readers in the USA
: please note on UK Macs the Trash is called the
: Wastebasket).
: Version two has not been run on an iMac yet but doesn’t
: seem to work on the G3.
: Any help , assistance or suggestions would be greatly
: appriciated. The full scripts are
: below.
: Michael
: ? Version one: tell application “Finder”
: activate
: empty trash
: tell application “Finder”
: shut down
: end tell
: end tell
: ? Version two: tell application “Finder”
: delete (every file of folder “Wastebasket” of
: desktop ¬
: whose creation date is greater than (the current date) ¬
: - 24 * hours)
: empty Wastebasket
** It’s version two that produces the error message! **
: tell application “Finder”
: shut down
: end tell
: end tell
Version two also has a few problems in that it uses the Finder’s ‘whose’ filter, which is known to have a bug in its numerical comparisons (dates, sizes, etc.). You’re also attempting to zap files which are less than a day old, and ‘delete’ only moves stuff to the Wastebasket - if it’s already there, it won’t make any difference. You may also want to consider selecting items by their modification date rather than their creation date.
Anyway, to cut the waffle, this should do what you want. Hope it helps:

-- Pre-calculate the date 24 hours ago
set aDayAgo to the (current date) - 1 * days
tell application "Finder"
	-- Create a temporary folder on the desktop to hold the items you don't want to lose (yet)
	make folder at the desktop with properties {name:"temporary storage"}
	-- Check the modification date of every item in the Wastebasket
	-- Move anything that was last modified less than a day ago to the temporary folder
	get every item of the trash
	repeat with thisItem in the result
		if the modification date of thisItem comes after aDayAgo then
			move thisItem to folder "temporary storage"
		end if
	end repeat
	-- Empty the Wastebasket of all remaining items
		empty trash
	on error -- the Wastebasket was empty, ignore it
	end try
	-- Move the items from the temporary folder back to the Wastebasket
	delete every item of folder "temporary storage"
	-- Delete the temporary folder itself
	delete folder "temporary storage"
	shut down
end tell


Thanks a lot Nigel!
This is only my first go at writing scripts for real, so you’ll forgive me if I kneel before you in humility and thankfulness! < smiles >. Joking apart thanks again and if it works I’ll let you know!