 |
 |
Force Empty Trash?
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: May 2001
Location: Winnipeg, MB Canada
Status:
Offline
|
|
I have written a script, and emptying the trash is the first thing to execute. I am getting an error message "The trash could not be deleted due to an error -15284". I was wondering if there was a way to force the Empty Trash (like the option key process).
Kimbo
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2001
Status:
Offline
|
|
As near as I can tell, the error you're getting appears to be due to locked items in the trash, and I can't think of another situation where this error would occur. If this is the case, the items must be unlocked before deleting. If you wanted to do this the applescript way, here are 2 examples:
If locked items are not expected to be buried in subdirectories in the trash, replacing your current tell Finder block with the following should work:
Code:
tell application "Finder"
set trash_List to list folder (path to trash)
repeat with i in trash_List
set trash_File to (trash as string) & contents of i
try
set locked of alias trash_File to false
end try
end repeat
empty the trash
end tell
If locked items may be buried in subfolders in the trash, it gets a little more complicated, but can be done. The following routine can be used, and the remainder of your script inserted as indicated (immediately before the "end run" statement):
Code:
on process_Trash(trash_File) -- sorts out subdirectories, then unlocks files
set fileInfo to info for trash_File
if folder of fileInfo then
process_Folder(alias trash_File)
else
tell application "Finder"
set locked of alias trash_File to false
end tell
end if
end process_Trash
on process_Folder(aFolder) -- sends files in subdirectories of trash to be unlocked
set fldr_List to list folder aFolder
repeat with i in fldr_List
set trash_File to (aFolder as string) & contents of i
process_Trash(alias trash_File)
end repeat
end process_Folder
on run -- Script starts & ends here. Remainder of script could be inserted as indicated below.
set trash_List to list folder (path to trash)
repeat with i in trash_List
set trash_File to (path to trash as string) & contents of i
process_Trash(trash_File)
end repeat
tell application "Finder"
empty the trash
end tell
-- rest of script would go here
end run
Don't really know of another way to force the trash to empty if it otherwise won't. I'm sure if there's some other reason it won't empty, it will tell you! Hope this helps.
cheers, acur
|
|
|
| |
|
|
|
 |
|
 |
|
Whisper
|
|
Originally posted by Kimbo:
I have written a script, and emptying the trash is the first thing to execute. I am getting an error message "The trash could not be deleted due to an error -15284". I was wondering if there was a way to force the Empty Trash (like the option key process).
Kimbo
Well hmm... A folders is really just a file which contains (among other things) a list of file "pointers". Each item on the list is a "pointer" to a file that's in the folder. The Trash is really just a folder that you can't normally access directly. So if the Trash Can is giving you crap about emptying it, you could tell a Hex Editor to open up the Trash, and delete the offending file's entry. There may or may not be more to it than that. One thing in particular is that I have no clue if you'd also have to let the File Manager know that the file no longer exists, or if it's smart enough to figure that out on its own. And I think HFS/HFS+ do lots of cross referencing of files, so you'd prolly have to edit a few other files that you're not even supposed to know exist. Also, I don't think you can do this through AppleScript. But it will (theoretically) delete any file, without regard to its locked/unlocked status, or any of those pesky "Unable to delete file because it cannot be found" errors, which drive me bonkers.
Note that I do not recomend this method, I just thought I'd toss it out.
-Whisper
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|