Erratum -- "the successful command-line phrase above" is:
mdfind -onlyin / 'kMDItemFSName == "Finding Joy in Combinators.pdf"' >
/Users/cwalston/factor/mdfind.txt
~CW Alston
On Mon, Oct 21, 2013 at 12:49 AM, CW Alston <cwalsto...@gmail.com> wrote:
> Greetings, folks -
>
> I'm trying to compose a find-file utility that takes advantage
> of Spotlight's index on the Mac (I'm running 10.6.8). A simple search
> tool built on find-file from io.directories.search works, even with
> space-separated filenames, e.g., "Finding Joy in Combinators.pdf", but
> it walks the entire hierarchy & I want to avoid that delay.
> Here's that word, using locals:
>
> :: find-file* ( filename -- path/f ) ! REALLY LONG... CAN WE USE SPOTLIGHT?
> filename :> this-filename
> "/" t [ file-name this-filename = ] find-file
> ;
>
> I found a command-line incantation that does the trick in Terminal:
>
> ➜ ~ git:(master) ✗ mdfind -onlyin / 'kMDItemFSName == "Finding Joy in
> Combinators.pdf"'
>
> /Applications/Programming Languages/Functional Languages/Concatenative
> languages/Joy (programming language) folder/Finding Joy in Combinators.pdf
> ➜ ~ git:(master) ✗
>
> I can successfully send the Terminal output to a file:
>
> ➜ ~ git:(master) ✗ mdfind -onlyin / 'kMDItemFSName == "Finding Joy in
> Combinators.pdf"' > /Users/cwalston/factor/mdfind.txt
> ➜ ~ git:(master) ✗
>
> But I'm at loggerheads trying to compose a <process> command that does the
> same from
> within Factor. My latest attempt is this:
>
> : tri-quotes-surround ( seq -- seq' ) """"""" """"""" surround ; ! goofy,
> but seems to work
>
> :: <mdfind-request> ( filename -- seq )
> "'kMDItemFSName == " filename tri-quotes-surround append "'"
> append ;
>
> : <mdfind-process> ( filename -- process )
> <mdfind-request> ! ( -- seq )
> '[ "mdfind" , "-onlyin" , "/" , _ , ">" ,
> "/Users/cwalston/factor/mdfind.txt" , ]
> { } make ! ( -- seq )
> <process> swap >>command
> t >>detached clone ! ( -- process )
> ;
>
> And then, "Finding Joy in Combinators.pdf" <mdfind-process> contains a
> command
> sequence that looks like this:
> {
> "mdfind"
> "-onlyin"
> "/"
> "'kMDItemFSName == \"Finding Joy in Combinators.pdf\"'"
> ">"
> "/Users/cwalston/factor/mdfind.txt"
> }
>
> -which I thought translates to the successful command-line phrase above:
>
> mdfind -onlyin / 'kMDItemFSName == "Finding Joy in Combinators.pdf"'
>
> But it does't produce the desired result in my word that calls
> <mdfind-process> :
>
> SYMBOL: file-process
> SYMBOL: file-process-status
> : mdfind-file ( filename -- seq ) ! Using Spotlight index
> <mdfind-process> run-process
> dup file-process set wait-for-process file-process-status set ! FOR
> TESTING
> "/Users/cwalston/factor/mdfind.txt" utf8 file-contents
> ;
>
> e.g.,
> IN: scratchpad "Finding Joy in Combinators.pdf" mdfind-file
>
> --- Data stack:
> ""
> IN: scratchpad
>
> Meaning, nothing is written to /Users/cwalston/factor/mdfind.txt !
> Ideally, I'd rather stream the result directly to Factor, but I can't
> figure that out
> until I get the <process> command straight.
>
> Any insights welcome! Thanks,
> ~Charles Alston
>
> --
> *~ Memento Amori*
>
--
*~ Memento Amori*
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk