select_in_finder
I love find almost as much as I love DTerm (full disclosure: I work for Decimus Software), but, being a Mac user, sometimes I want to handle my files with the Finder, too.
Unfortunately, combining the shell with the Finder requires AppleScript, which is really painful when all you want to do is select some files. However, with rb-appscript things are somewhat better—we can trade the painful AppleScript for some (slightly ugly, if you ask me, but RubyOSA wasn’t working for me) Ruby.
As an example of its use, the command:
find . -name '*.jpg'
will return the paths of all the jpgs in the working directory (and recursively, in fact). Selecting them in the Finder would be useful if we wanted to email them to someone, so wouldn’t it be nice to just write something like:
find . -name '*.jpg' |
select_in_finder
and drag them over to Mail?
That was the idea behind this script.
#!/usr/bin/env ruby -rubygems
require "appscript"
Appscript::app('Finder').
selection.
set(STDIN.
readlines.
collect do |line|
MacTypes::FileURL.
path(line.strip).to_alias
end)
It doesn't do any error checking, and you should bear in mind that the Finder will simply ignore any files that aren't in its displayed folder when in column mode; in list mode it is able to select divergent paths correctly.
But when all’s said and done, it's pretty sweet to be able to, say, select all the unknown screenshots in the current folder's git repository:
git status |
grep modified |
awk '{print $3}' |
select_in_finder
Download select_in_finder, put it somewhere in your $PATH, and enjoy. Don't forget to email me your comments, suggestions, and adulation!