Hi folks,

 I've posted a new gist for
spotlight.factor<https://gist.github.com/cwalston/7425403>w/ filename
& Factor formatting.
I think I dealt with most of Alex's red-lines, & I shed the string
constants.
The whole thing is much shorter. The included examples work on my machine.

 The file can be USE:d from the listener if you give it a folder in your
'work'.

 After a long divagation, looks like I've wound up back where John & Alex
suggested I start, 3 weeks ago. Well, like I was warned in the Boy Scouts,
when you wander lost in the woods, you tend to go 'round in circles.
Just couldn't see how to get on from there without a compass (or native
guides),
& I did learn a lot along the way. Still needs some improvement (maybe bug
fixes, too).

 In particular, I'd like to memoize an API call to
MDSchemaCopyAllAttributes(),
but I'm better at Chinese than C. Pointers on alien-invoke, or what else to
use?

Thanks,
CW Alston



On Mon, Nov 11, 2013 at 4:29 PM, John Benediktsson <[email protected]> wrote:

> I agree with Alex's comments and would add one thing, which is if you like
> all your constants (so you don't have to remember them), instead of
> creating all the specialized words like by-Author, maybe just have the
> constants and then a generic by-attribute so using Alex's "mdfind":
>
>     CONSTANT: Author "kMDItemAuthor"
>
>     : mdfind-by ( value name -- results )
>         swap "%s = '%s'" sprintf mdfind ;
>
> So you could do:
>
>     IN: scratchpad "Stephen King" Author mdfind-by
>
>
>
>
>
>
>
>
>
> On Mon, Nov 11, 2013 at 3:39 PM, CW Alston <[email protected]> wrote:
>
>> Phew! - let me co-sign you on that, with a hearty Thanks, Alex!
>>
>>  I really appreciate the time you took to run a fine-toothed comb through
>> through
>> such a heap of code. Lots to chew on, and learn from. All your points
>> make sense.
>> (Sorry about all the SHOUTING, lol - just a visual crutch for me, but I
>> can wean
>> myself away from stylistic improprieties).
>>
>>  Edified, encouraged, let me see what improvements I can come up with.
>>
>> Thanks again. Back to the future (though that may take a while...),
>> ~cw
>>
>>
>> On Mon, Nov 11, 2013 at 10:57 AM, Alex Vondrak <[email protected]>wrote:
>>
>>> I have too much formatting (and email always has a way of wrecking
>>> that), so I put a comment on the gist:
>>> https://gist.github.com/cwalston/7368493#comment-948159
>>>
>>> Have a good one,
>>> --Alex Vondrak
>>>
>>>
>>> On Mon, Nov 11, 2013 at 1:28 AM, CW Alston <[email protected]> wrote:
>>> > Hi all-
>>> >
>>> >  Re-factoring 'spotlight.factor' worked better than SlimFast. "Look
>>> Ma, no
>>> > files"!
>>> > Much obliged for the pointers on how to set up commands for
>>> > "with-process-reader".
>>> >
>>> >  I've replaced the code in the Gist previously posted with a revised,
>>> > self-contained
>>> > version. Please do take a look & beat on the code. It should compile
>>> fine
>>> > simply
>>> > pasted whole in the listener. I'm sure many query formatting cases
>>> aren't
>>> > covered yet.
>>> >
>>> >  There are a passel of terminal examples to try to emulate at the end
>>> of the
>>> > file.
>>> > As there are myriad variations in formatting terminal commands, it
>>> would be
>>> > good to
>>> > have as general an interface from Factor as possible. I'd like to
>>> develop
>>> > 'spotlight'
>>> > into a practical utility. Suggestions? Feedback appreciated.
>>> >
>>> > Thanks kindly,
>>> > ~ CW Alston
>>> >
>>> >
>>> >
>>> > On Sat, Nov 9, 2013 at 7:43 PM, CW Alston <[email protected]>
>>> wrote:
>>> >>
>>> >> Great help, folks!
>>> >>
>>> >> I think I can figure this out now. With a l'il more elbow-grease &
>>> your
>>> >> pointers,
>>> >> I'd like to make the 2 crutch files disappear, & access the MetaData
>>> index
>>> >> in all its glory directly. That certainly would make this a much more
>>> >> independent,
>>> >> self-contained utility. Useful breakdown, Alex. Back to the drawing
>>> board.
>>> >>
>>> >> Thanks, all -
>>> >> ~cw
>>> >>
>>> >>
>>> >>
>>> >> On Sat, Nov 9, 2013 at 8:36 AM, John Benediktsson <[email protected]>
>>> >> wrote:
>>> >>>
>>> >>> This works for me, it has to be a string or sequence of strings:
>>> >>>
>>> >>> IN: scratchpad { "mdfind" "kMDItemComposer == 'Andrea Bocelli'" }
>>> utf8 [
>>> >>> lines ] with-process-reader
>>> >>>
>>> >>> Anyway, I love this vocab and getting it to work is like 95% of the
>>> >>> challenge, I think it would be fun to modify it to not require the
>>> >>> indirection and contribute it to the main repository if you're
>>> interested!
>>> >>>
>>> >>> Best,
>>> >>> John.
>>> >>>
>>> >>>
>>> >>>
>>> >>> 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
>>> >>>
>>> >>>
>>> >>
>>> >>
>>> >>
>>> >> --
>>> >> ~ 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
>>
>>
>


-- 
*~ Memento Amori*
------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to