How to save Finder search results (filename list) to a text file?
When I use Finder to locate a set of files, I want to save the list of files to a text file (preferably with path names).
I know I can open the shell and use 'find', but what's the point of having a GUI if you have to remember the syntax for shell commands still to get the job done? :)
Is there a way to save the result list to a file?
Create a simple AppleScript:
on open (fileList)
set outFile to (choose file name with prompt "Output file:" default name "FileList.txt")
open for access outFile with write permission
repeat with oneFile in fileList
write (POSIX path of oneFile) & "
" to outFile
end repeat
close access outFile
end open
... and save it as an application. To use it, select all in the search window, then drop the list of files on the AppleScript. It can also be used with any other sort of list-of-files-from-the-Finder.
EDIT: If you want to set this up as a service rather than a droplet (and are running Snow Leopard), create this in Automator rather than AppleScript, use the "Service" template, set the "service receives select" pop-up to "files and folders", add a Run AppleScript action, paste in the above script, but with on run {fileList, parameters}
... end run
instead of on open (fileList)
... end open
. Save it with some appropriate name, and then to use it, select the files, right-click (or control-click), and select Services > yourservicename from the pop-up.
the find
command is a standard unix command, it is not an interface to spotlight.
The command line interface to spotlight is the mdfind
command. For example to find files called foo.txt one would type mdfind -name foo.txt
Like any other Unix command, its output can be redirected into another file, using the >
operator. for example, mdfind -name foo.txt > bar.txt
would do the above search for files called foo.txt, and put the results into a file called bar.txt in the current directory.
For more info on the command line interface to spotlight, check out the mdfind manpage