I guess io.launcher needs better examples...  They show how launch
descriptors are either strings or arrays, but they don't explain what
each means.  The details change by OS backend, but for Unix it works
like this:

- Given a sequence launch descriptor, { "a" "b" "c" }, io.launcher
uses exec-with-path
(http://docs.factorcode.org/content/word-exec-with-path,unix.process.html)
supplying "a" as the filename (the command to execute) and { "a" "b"
"c" } as ARGV: http://notabug.com/2002/coherent/man/argv.html  Thus,
each element of the array (past the first) should be a *single* token,
as provided to ARGV.

So instead of

  { "find -maxdepth 1 -type d" } utf8 [ lines ] with-process-reader .

or

  { "find" "-maxdepth 1 -type d" } utf8 [ lines ] with-process-reader .

or

  { "find" "-maxdepth 1" "-type d" } utf8 [ lines ] with-process-reader .

all of which break, you'd have to run

  { "find" "-maxdepth" "1" "-type" "d" } utf8 [ lines ] with-process-reader .

- Given a string launch descriptor, "a b c", the string gets
*tokenized* into such an array:
http://docs.factorcode.org/content/word-tokenize%2Csimple-tokenizer.html

Thus

  "find -maxdepth 1 -type d" utf8 [ lines ] with-process-reader .

works, because

  "find -maxdepth 1 -type d" tokenize

gives

  V{ "find" "-maxdepth" "1" "-type" "d" }

which is used as the launch descriptor.

Therefore, much like the examples I sent a few weeks back, I suspect
the following will work:

  "mdfind \"kMDItemComposer == 'Dylan'\"" utf8 [ lines ] with-process-reader .

My point in the examples I gave you a few weeks ago was that the
*real* thing to watch out for here is unexpected input or results that
may give non-zero exit statuses.  E.g., on my Linux box,

  "find /proc -name blah" utf8 [ lines ] with-process-reader

throws an error Factor-side because find's exit status is 1, since
find didn't have permission to read /proc.

Hope that helps,
--Alex Vondrak

On Fri, Nov 8, 2013 at 10:11 PM, CW Alston <[email protected]> wrote:
> Hi John,
>
> I can't get your suggestion to work with mdfind:
>
>> Why go through the indirection of a shell script and a query results
>> rather than just preparing
>> a sequence of args and then grabbing all the results, e.g.
>> { mdfind "kMDItemAuthor == '*MyFavoriteAuthor*'" } utf8 [ lines ]
>> with-process-reader
>
> - Trying this command format (with a different MD Attribute) works fine in
> the terminal:
>
> ➜  ~ git:(master) ✗ mdfind "kMDItemComposer == 'Dylan'"
> /Applications/Music/iTunes/iTunes Music/Bob Dylan/Planet Waves/11 Wedding
> Song.m4a
> /Applications/Music/iTunes/iTunes Music/Bob Dylan/Planet Waves/10 Never Say
> Goodbye.m4a
> /Applications/Music/iTunes/iTunes Music/Bob Dylan/Planet Waves/09 You Angel
> You.m4a
> /Applications/Music/iTunes/iTunes Music/Bob Dylan/Planet Waves/08 Dirge.m4a
> ...
> ➜  ~ git:(master) ✗
>
> - But trying the same command in the with-process-reader format fails in the
> listener:
>
> IN: scratchpad { mdfind "kMDItemComposer == 'Dylan'" } utf8 [ lines ]
> with-process-reader
>
> Process exited with error code 254
>
> Launch descriptor:
>
> T{ process
>     { command { mdfind "kMDItemComposer == 'Dylan'" } }
>     { environment H{ } }
>     { environment-mode +append-environment+ }
>     { stdout T{ fd { disposed t } { fd 23 } } }
>     { group +same-group+ }
>     { status 254 }
>     { pipe
>         T{ pipe
>             { in T{ fd { disposed t } { fd 19 } } }
>             { out T{ fd { disposed t } { fd 23 } } }
>         }
>     }
> }
> ---------------
> -Switching single & double quotes around doesn't help:
> IN: scratchpad { mdfind 'kMDItemComposer == "Dylan"' } utf8 [ lines ]
> with-process-reader
>
> Error
> No word named “'kMDItemComposer” found in current vocabulary search path
> (however, mdfind 'kMDItemComposer == "Dylan"' works in terminal)
>
> ---------------
> -Ok, so trying various permutations of single, double, triple quotes in the
> command:
> IN: scratchpad { """mdfind "kMDItemComposer == 'Dylan'"""" } utf8 [ lines ]
> with-process-reader
>
> Process exited with error code 255
> (however, mdfind "kMDItemComposer == 'Dylan'" works in terminal)
>
> ---------------
> IN: scratchpad { """mdfind 'kMDItemComposer == "Dylan"'""" } utf8 [ lines ]
> with-process-reader
>
> Process exited with error code 255
> (however, mdfind 'kMDItemComposer == "Dylan"' works in terminal)
>
> ---------------
> IN: scratchpad { "mdfind" """'kMDItemComposer == "Dylan"'""" } utf8 [ lines
> ] with-process-reader
>
> Process exited with error code 1
> (again, mdfind 'kMDItemComposer == "Dylan"' works in terminal)
>
> ---------------
> -Using the code from the spotlight.factor vocab works like the terminal
> example above:
> IN: scratchpad "Dylan" by-Composer mdfind .
>
> {
>     "/Applications/Music/iTunes/iTunes Music/Bob Dylan/Planet Waves/11
> Wedding Song.m4a"
>     "/Applications/Music/iTunes/iTunes Music/Bob Dylan/Planet Waves/10 Never
> Say Goodbye.m4a"
>     "/Applications/Music/iTunes/iTunes Music/Bob Dylan/Planet Waves/09 You
> Angel You.m4a"
>     "/Applications/Music/iTunes/iTunes Music/Bob Dylan/Planet Waves/08
> Dirge.m4a"
>     "/Applications/Music/iTunes/iTunes Music/Bob Dylan/Planet Waves/07
> Forever Young (Continued).m4a"
>     "/Applications/Music/iTunes/iTunes Music/Bob Dylan/Planet Waves/06
> Forever Young.m4a"
>     ...
> }
>
> I'm probably missing something simple, but I haven't found a way to get
> mdfind to work in
> a process command, and reading the output stream-lines.
> Hence, my relief at getting "a shell script and a query results" approach to
> work without blowing up.
>
> I agree, it would be much more elegant to craft a solution in the form of
> your suggestion.
> If anyone can cook one up, that would really be sweet! I just want to access
> the Spotlight
> MetaData Index from Factor in the simplest possible way. Meanwhile, I'll
> exercise spotlight;
> baroque as it is, it gets me to the MetaData, and does find things.
>
> Thanks,
> Charles
>
>
>
> On Fri, Nov 8, 2013 at 8:37 AM, John Benediktsson <[email protected]> wrote:
>>
>> Hi,
>>
>> Why go through the indirection of a shell script and a query results
>> rather than just preparing a sequence of args and then grabbing all the
>> results, e.g.
>>
>> { mdfind "kMDItemAuthor == '*MyFavoriteAuthor*'" } utf8 [ lines ]
>> with-process-reader
>>
>>
>>
>>
>>
>> On Fri, Nov 8, 2013 at 1:55 AM, CW Alston <[email protected]> wrote:
>>>
>>> (Oops- forgot to sign in)
>>> Thanks for the heads-up, Björn - try this link, folks.
>>> ~cw
>>>
>>>
>>> On Fri, Nov 8, 2013 at 1:14 AM, CW Alston <[email protected]> wrote:
>>>>
>>>> Thanks for the heads-up, Björn - try this link.
>>>>
>>>> ~cw
>>>>
>>>>
>>>> On Fri, Nov 8, 2013 at 12:49 AM, Björn Lindqvist <[email protected]>
>>>> wrote:
>>>>>
>>>>> 2013/11/8 CW Alston <[email protected]>:
>>>>> > Greetings, Factorials -
>>>>> >
>>>>> > I've posted a vocab to the pastebin, a Factor interface to OS X
>>>>> > Spotlight.
>>>>> > Pardon the length; this should be split into at least 2 code files &
>>>>> > a docs file. Just seems best to show everything together for the
>>>>> > post.
>>>>>
>>>>> Check your link, it doesn't go anywhere. :) Perhaps try
>>>>> https://gist.github.com/ for long-lived pastes because they dont
>>>>> delete them after a few days.
>>>>>
>>>>>
>>>>> --
>>>>> mvh/best regards Björn Lindqvist
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> ~ Memento Amori
>>>
>>>
>>>
>>>
>>> --
>>> ~ Memento Amori
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> November Webinars for C, C++, Fortran Developers
>>> Accelerate application performance with scalable programming models.
>>> Explore
>>> techniques for threading, error checking, porting, and tuning. Get the
>>> most
>>> from the latest Intel processors and coprocessors. See abstracts and
>>> register
>>>
>>> http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
>>> _______________________________________________
>>> Factor-talk mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>>
>>
>
>
>
> --
> ~ Memento Amori
>
> ------------------------------------------------------------------------------
> November Webinars for C, C++, Fortran Developers
> Accelerate application performance with scalable programming models. Explore
> techniques for threading, error checking, porting, and tuning. Get the most
> from the latest Intel processors and coprocessors. See abstracts and
> register
> http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
> _______________________________________________
> Factor-talk mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>

------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most 
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to