1 ! Copyright (C) 2013 Charles Alston, John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays formatting help.stylesheet io io.encodings.utf8
4 io.launcher io.pathnames io.styles kernel locals memoize
5 namespaces sequences sequences.generalizations splitting
11 ! -need to test sudo-mdutil; intercept auth prompt
12 ! -handle case-sensitivity properly (OS X)
13 ! -test composing variant shell command constructions,
14 ! i.e., those which do or don't need spaces, parens,
15 ! single quotes, etc. (work through examples at end of file)
16 ! -access o.e.d & calculator through spotlight
17 ! -emit some sort of 'not-found' msg for unsuccessful search
21 : attr== ( item-name attr-name -- string )
22 swap "%s == '%s'" sprintf ;
24 : attr!= ( item-name attr-name -- string )
25 swap "%s != '%s'" sprintf ;
27 : attr> ( item-name attr-name -- string )
28 swap "%s > '%s'" sprintf ;
30 : attr>= ( item-name attr-name -- string )
31 swap "%s >= '%s'" sprintf ;
33 : attr< ( item-name attr-name -- string )
34 swap "%s < '%s'" sprintf ;
36 : attr<= ( item-name attr-name -- string )
37 swap "%s <= '%s'" sprintf ;
39 : attr&& ( attr1 attr2 -- string )
42 : attr|| ( attr1 attr2 -- string )
47 : run-process-output ( command -- seq )
48 utf8 [ read-lines ] with-process-reader ;
52 : mdfind ( query -- results )
53 "mdfind -onlyin . %s" sprintf run-process-output ;
55 : mdfind. ( query -- )
56 mdfind [ dup <pathname> write-object nl ] each ;
59 absolute-path "mdls" swap 2array run-process-output
62 : mdutil ( flags on|off volume -- seq )
63 [ "mdfind" swap "-" prepend "-i" ] 2dip 5 narray
66 : mdimport ( path -- seq )
67 absolute-path "mdimport " prepend run-process-output ;
69 : mdimport-with ( path options -- seq )
70 swap absolute-path "mdimport %s %s" sprintf run-process-output ;
72 MEMO: kMDItems ( -- seq )
73 "mdimport -A" run-process-output
74 [ "'kMDItem" head? ] filter
75 [ "\t" split harvest [ but-last rest ] map ] map ;
78 kMDItems table-style get [
81 [ [ 64 wrap-string write ] with-cell ] each