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


Click here to return to the 'Make 'rm' behave like the Finder trash' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Make 'rm' behave like the Finder trash
Authored by: krishna on May 13, '03 04:59:03PM

Reading this post got me thinking about the proper 'mac' way to do this, so I made an ugly ugly ugly tcsh alias that does something similar.

I prefer mine because it uses the macos's own trash can functions to trash something, including:

* the update of open finder windows
* the little 'ssh' sound
* being able to trash a whole directory at once (and pretty quickly)
* automatic renaming of files in the trash to not overwrite others

rather than relying on the underlying UNIX implementation, (location of trash directory, any other notifications that happen when a file is removed, etc) which conceivably might change with new os revisions.

Note that it makes an assumption about the current finder device being the same as where you are in the terminal (which is fine for me, because I only have one hard drive on my tibook). Note that this should all be one one single line (replace each newline below with a space).

alias del 'perl -MCwd -e ' "'"
'for (@ARGV) { m{^/} or $_ = cwd."/".$_; s{/}{:}g;}
system ("osascript", "-e", "tell application \"finder\"", map({("-e", "delete \"$_\"")} @ARGV),
"-e", "end tell") ' "'" '\!*'

Then try it out:

touch foo
mkdir somedir
del somedir foo

Improvements:
* this really should be a short perl script, rather than an alias, for readability
* this doesn't handle '.' or '..' in the paths
* I don't know of a proper applescript or other function to transform a relative or absolute unix pathname to a mac pathname (which is what applescript seems to require). That would handle the case of the file being anywhere in the unix filesystem.



[ Reply to This | # ]
Make 'rm' behave like the Finder trash
Authored by: krishna on May 13, '03 05:46:49PM

Re: converting unix pathnames to regular ones, I think something like

set thefile to get POSIX file "/Users/krishna/foo.txt"
set thefilename to path to thefile
tell application "finder"
delete thefilename
end tell

should do the trick, but I get all kinds of different weird errors (being just an applescript beginner).



[ Reply to This | # ]