How to save Finder search results (filename list) to a text file?

5,223

Solution 1

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.

Solution 2

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

Solution 3

You can right-click on the results and select "Copy N items". That will copy the file names without their path to the clipboa–er, pasteboard.

Not ideal, but it might be start?

Solution 4

There also exist many third party GUI interfaces to spotlight, such as filespot. I am sure one of these must have comprehensive export options.

Share:
5,223

Related videos on Youtube

Stabledog
Author by

Stabledog

Updated on September 18, 2022

Comments

  • Stabledog
    Stabledog over 1 year

    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?

  • Stabledog
    Stabledog about 14 years
    Yes, I'm well aware of the 'find' command, that's why I mentioned it in the question. I'm trying to do this in the GUI.
  • Stabledog
    Stabledog about 14 years
    Well yes, it is a start. I didn't even think that far :)
  • JonnieCache
    JonnieCache about 14 years
    my point was, the find command does not actually use spotlight so if you or anyone else did end up giving up and piping the results from the command line, you would be bypassing the spotlight index and causing a HUGE performance hit. any gui that achieved this would simply be a text field to enter your search term, and not much else. this is basically a command line anyway surely?
  • Stabledog
    Stabledog about 14 years
    Not sure what you're saying: Finder is using an index. It's showing me a list of the files found. It's quick and efficient. It knows the names of all the items found. I want a way to retrieve those names into the clipboard, that's all. This really doesn't have any significant performance hit.
  • Stabledog
    Stabledog about 14 years
    However, I didn't know about 'mdfind', so that part is indeed useful. Even worse, I stopped reading when it sounded like you were recommending 'find', so now I've earned the "sloppy reader" badge :)
  • JonnieCache
    JonnieCache about 14 years
    find does not use any index. it simply walks the directory tree. this is very slow, but on some unix systems where there is no indexing system set up, there is no alternative. mdfind behaves in the same way (roughly) but it uses spotlight's advanced indexing system and is therefore orders of magnitude faster than the normal find command. I simply wanted, in the eventuality that you or someone else does end up using the command line to solve this problem, to make sure they used the spotlight index rather than the blunt directory walk that find does.
  • Stabledog
    Stabledog about 14 years
    Aye, thanks. I've been playing with mdfind a bit now... it's fast, that's nice. But it doesn't seem to have a lot of options for selecting and filtering. Still, because it's fast I can pipe the output to grep and get what I want quickly. Thanks for the helpful tip.
  • Stabledog
    Stabledog about 14 years
    Filespot looks interesting. Unfortunately, the download links are 404... and Google doesn't seem to offer alternative sources. Any idea what's going on with that? I sent them email, perhaps they'll fix the link.
  • Stabledog
    Stabledog about 14 years
    Excellent! I will definitely try that.