My Custom LocateFiles( Function

Here is a custom function you can use to generate a list of all the locations of any file you enter as the parameter. The file should include the file extension along with the file name. Without using the file extension you could end up with a whole bunch of unexpected files added to the output. If you simply use “” as the file name it will gather the info for the current database.

registercustomfunction “LOCATEFILES”,1,{arrayfilter(arraynumericsort(arrayfilter(shellscript(
||| mdfind “kMDItemFSName=’|||+?(•1=”",info(“databasefilename”),•1)+|||’"|||)
,cr(),||| superdate(val(nthline(fileinfo(import()),5)),
val(nthline(fileinfo(import()),6)))+tab()+import() |||),cr()),cr(),
|||superdatestr(val(arrayfirst(import(),tab())))+tab()+arraylast(import(),tab()) |||)}

After running the above registration code you can use the locatefiles( function simply like this:


This will produce a list of all locations of my images.gif file on my system arranged in chronological order like this:

This method uses the same indexed file database as Spotlight. A shellscript( using mdfind gets the list of all the file paths then an arrayfilter( adds on the superdate of the last date the file was modified for each file followed by an arraynumericsort( to get them in chronological order with a final arrayfilter( to convert the superdates to a text pattern with the date and time last modified.

It was interesting how it turned up some long forgotten backup copies of various files including some old Panorama TimeLapse versions.