How would I view a list of file paths in a Finder window from command line output?

Solution 1:

How about temporarily assigning them all a unique label (maybe using something like tag), and then making a Finder smart folder for that label?

Here's what I did:

  1. Install tag with brew install tag.
  2. In Finder, File > New Smart Folder.
  3. Click "This Mac".
  4. Click +, and add "Tags" "Is" temp0. (This will get replaced later with a new temporary tag.)
  5. Click Save, and save it as something like /Users/youruser/Library/Saved Searches/Custom Tag.savedSearch.
  6. Create a script like this (with SMART_FOLDER set to the path above, without the extension):
#!/bin/bash
set -e
SMART_FOLDER="/Users/youruser/Library/Saved Searches/Custom Tag" # without extension

# pass all arguments to find, and store in array
IFS=$'\n'
RESULTS=($(find "$@"))
unset IFS

# assign a temporary label
LABEL=temp$(date +%s)
tag -a "$LABEL" "${RESULTS[@]}"

# create a temporary savedSearch with the new label.
# if we just update it, Finder doesn't seem to notice.
sed "s/temp0/$LABEL/g" "$SMART_FOLDER.savedSearch" > "$SMART_FOLDER-$LABEL.savedSearch"
open "$SMART_FOLDER-$LABEL.savedSearch"

echo "Showing results for $LABEL. Press return to remove label."
read
tag -r "$LABEL" "${RESULTS[@]}"
rm "$SMART_FOLDER-$LABEL.savedSearch"
  1. Save it as something like ffind, somewhere in your default $PATH.
  2. Make it executable with chmod u+x ffind.
  3. Now you can use it just like find, e.g. ffind . -name '*.html'. It will pass its arguments to find, assign a temporary label to the results, create a temporary smart folder that finds that label, and open it. Then it will wait for you to press return.
  4. When you press return, it will clear the label from the files, and delete the temporary smart folder.

Solution 2:

A short AppleScript would work:

tell application "Finder" to reveal {"/Users/me/1.mp3" as POSIX file, "/Users/me/2.mp3" as POSIX file, "/Users/me/3.mp3" as POSIX file}

and you can run that directly from terminal with osascript:

osascript -e 'tell application "Finder" to reveal {"/Users/me/1.mp3" as POSIX file, "/Users/me/2.mp3" as POSIX file, "/Users/me/3.mp3" as POSIX file}'

I'm not proficient enough with shell to convert the find output to the above command (I'd rather use a text editor for this), but it should be doable.