I have a folder action that reads the name of an incoming file and performs
a search on a database. It then deletes the file and empties the trash.
Occasionally the dialogs below appear.
Emptying the trash
The operation cannot be completed because the item “00287156.txt” is in use.
Or
Emptying the trash
The operation cannot be completed because a required item is in use.
I have stripped down the code and it still generates those dialogs.
on adding folder items to this_folder after receiving these_items
tell application "Finder"
activate
repeat with i in these_items
set theFile to name of i as text
set theNewFileName to characters 1 thru -5 of theFile as text
delete i
end repeat
empty trash
end tell
end adding folder items to
‘warns before emptying’ is a property of the Finder’s trash object, not a parameter of ‘empty’. It’s equivalent to the “Show warning before emptying the Trash” setting in the Finder’s “Advanced” preference pane. When it’s ‘true’, the Finder displays an “Are you sure.?” message whenever an attempt is made to empty the trash manually using “Empty Trash.” in the “Finder” menu or the equivalent keystroke. It appears to have no effect when emptying the trash either by script or via the Trash icon in the Dock.
tell application "Finder"
set warns before emptying of trash to true -- or to 'false' to turn it off.
end tell
‘The operation cannot be completed because the item “00287156.txt” is in use.’ usually means that the item’s still open for access by some application. The application that created it might still be writing to it, or a less-than-robust script might have used ‘open for access’ on it and then errored before it could close it again, or the document might be sitting laughing at you from the Dock. If you can’t clear the item from the trash at all, try quitting the application, if that’s known, or logging out and logging in again. In the unlikely event that neither of these work, your system may need a little disk maintenance.