Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Use OS X's trash in a Finder-like way from Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use OS X's trash in a Finder-like way from Terminal
Authored by: Sesquipedalian on Apr 23, '10 10:50:32AM
It occurred to me after posting my previous comment that there is a much simpler way of accomplishing the goals of this hint. Moreover, this alternative method avoids the possible problems that others have posted about here, since it works not by emulating the process Finder uses when trashing things, but by actually having the Finder itself do the job.

To send files to the Trash using the command line, save the following code in a file on your Desktop called trash, make it executable (chmod +x ~/Desktop/trash) and store it somewhere on your bash $PATH (I recommend /usr/local/bin)

for arg in "$@"
if [ -e "$PWD/$arg" ]
osascript -e "tell application \"Finder\" to delete POSIX file \"$PWD/$arg\"" &>/dev/null
elif [ -e "$arg" ]
osascript -e "tell application \"Finder\" to delete POSIX file \"$arg\"" &>/dev/null
echo File not found

To empty the trash, this code will work nicely:
osascript -e "tell application \"Finder\" to empty trash"

To empty the trash securely, use this:

osascript -e "tell application \"Finder\" to empty trash with security"

EDIT: Updated the trash script's code to handle relative path arguments.

Edited on Apr 23, '10 11:31:41AM by Sesquipedalian

[ Reply to This | # ]
Just script the Finder via osascript
Authored by: GaelicWizard on Apr 24, '10 10:58:35AM

But, of course, this method fails completely in any situation where Finder won't cooperate, such as:
(1) when Finder isn't running.
(2) when AppleScript (via osascript) won't work, e.g. when ssh'd in.
(3) when Finder is blocked waiting for something else, e.g. with a modal dialogue box on screen.


Edited on Apr 24, '10 10:59:23AM by GaelicWizard

[ Reply to This | # ]