Empty trash w/ locked items

I have a script that I’ve written for a nightly backup to another drive, and once the backup is finished it puts the previous backup in the trash and empties the trash. My problem is there are locked items and I get an error every time the script tries to empty the trash. Is there an easy way to tell applescript to delete locked items (like holding option when doing ‘Empty trash’)???

As far as I know, there is no easy way to tell the trash to override the locked status of an item when emptying the trash.
You might try unlocking all the items in the trash prior to emptying.
grh

: Yep, just did a small test -
: tell application “Finder”
: set the locked of every file of folder “Trash”
: to false
: empty trash end tell
: – this works. hth -Toby
Even if you change “file” to “item” this script will fail. Test it with multiple locked items in sub folders, etc. Since the System considers the Trash a different type of container than a regular folder, the only consistent way for this method to work is to unlock all items before they are moved to the Trash.

: There are a couple of ways to go about this: 1. Hack the
: Finder to add a keyboard command for emptying the
: Trash (I use “T”). After doing so, Command-T
: empties the Trash. Using the OSAXEN “Sandi’s
: Additions,” you can then write a script that
: simulates Command-Option-T (TypeText “t”
: with Command and Option) which empties the Trash of
: all items including locked items.
: I believe that the Akua Sweets OSAXEN allows you to do
: the same without hacking the Finder but I personally
: find the Akua Sweets dictionary to be a little
: difficult.
: 2. The other way is to unlock all items before you toss
: them into the Trash or unlock all items that reside in
: the Trash (set locked of every item of the entire
: contents of trash to false). I found that unlocking
: all items in the Trash created sporadic and unreliable
: results, especially with items locked in
: sub-sub-folders, etc. What does work consistently is
: to put the items in a temporary folder, unlock all the
: items, move them to the Trash, and then delete the
: Trash.
: Both methods work great. I’ll be more than happy to send
: you the scripts that I use/wrote.
If you prefer no to hack the finder there is a shareware control panel “Key Commander” which add command keys to any application, including “Finder” Set the key command T for trash and the use above type text. The cp can be found http://www.quadratic.com/shareware.shtml . Although it has 680x0 in its title it does work with power pc macintosh. I’ve used it with Systems 7.5 thru 8.6
Enjoy

: I have a script that I’ve written for a nightly backup to
: another drive, and once the backup is finished it puts
: the previous backup in the trash and empties the
: trash. My problem is there are locked items and I get
: an error every time the script tries to empty the
: trash. Is there an easy way to tell applescript to
: delete locked items (like holding option when doing
: ‘Empty trash’)???
Hi,
John’s Commands has a powerfull command : deleteFile
this command deletes any file without warning and without use the trash. You can’t undo!! use it in a repeat loop, it deletes one file at a time.
cya
Roberto

We had a copy of Speed Doubler 8 lying around and as it turns out it has an automatic copy scheduler already in it, and it has Smart Copying. So looks like I’m just going to end up using that (it takes 15mins to backup instead of 45). Thanks for all your help though :slight_smile:

: Even if you change “file” to “item”
: this script will fail. Test it with multiple locked
: items in sub folders, etc. Since the System considers
: the Trash a different type of container than a regular
: folder, the only consistent way for this method to
: work is to unlock all items before they are moved to
: the Trash.
Try moving the items out of the trash and into a new folder:

tell application "Finder"
   if not (folder "Empty Trash Temp" exists) then
      set theFold to make folder with properties {name:"Empty Trash Temp"}
   else
      set theFold to folder "Empty Trash Temp"
   end if
   move every item of trash to theFold
   set locked of every item of entire contents of theFold to false
   delete theFold
   empty 
end tell