Page 3 of 4

Re: Adding spotlight tags?

Posted: Tue Dec 08, 2009 5:08 pm
by ptujec
iRounak wrote:
Actually I like that much that I wish it would include file names and iptc keywords (which I use for tagging fotos) too.

what exactly do you want to search. If you could elaborate, I might be able to write a script. By file names, did you mean you wanted to search just files, not folders (which has nothing to do with comments)?


I have now figured out the codeline to search for file names.

Code: Select all

set thecmd to "mdfind   -name -onlyin ~ " & thequery


But I don't know how I can combine it to have the script search for both comments and file names

Re: Adding spotlight tags?

Posted: Tue Dec 08, 2009 5:22 pm
by iRounak
But I don't know how I can combine it to have the script search for both comments and file names

Code: Select all

set thequery to "pwd"
set thecmd to "mdfind  'kMDItemDisplayName == " & quote & thequery & "*" & quote & "wc" & " || kMDItemFinderComment == " & quote & thequery & "*" & quote & "wc'"
do shell script thecmd

Re: Adding spotlight tags?

Posted: Tue Dec 08, 2009 8:05 pm
by ptujec
Ok now I'm close. I also found out that the command for iptc keywords is "kMDItemKeywords". The only thing which is still buggin me is that it only seems to search for the exact query. So it will find a file named "The test file" with the query "test file" but not with the query "file test".
Any idea?

Re: Adding spotlight tags?

Posted: Wed Dec 09, 2009 3:44 am
by iRounak
Ok now I'm close. I also found out that the command for iptc keywords is "kMDItemKeywords".

If this is correct, then the script should be:

Code: Select all

set thequery to "pwd"
set thecmd to "mdfind  'kMDItemDisplayName == " & quote & thequery & "*" & quote & "wc" & " || kMDItemFinderComment == " & quote & thequery & "*" & quote & "wc" & " || kMDItemKeywords == " & quote & thequery & "*" & quote & "wc'"
do shell script thecmd


The only thing which is still buggin me is that it only seems to search for the exact query.

No, that is not true.
The search query "Paris" Matches “Paris”, “paris”, “I love Paris”, “paris-france.jpg”, and hopefully also “Comparison”.

So it will find a file named "The test file" with the query "test file" but not with the query "file test".


That calls for a different script which will take the words "file" and "test" as two separate queries and present you the aggregated results.

I suggest:
you type in your search query as "test" or just "file" instead of "file test" or "test file" and once you get the results, then you can:
type the other word so that LaunchBar narrows down the search results. (Unless, the search query "file"/"test" takes unbearable amount of time, in which the case you will have to write an entirely different script than the one suggested above.)

Re: Adding spotlight tags?

Posted: Wed Dec 09, 2009 10:28 am
by edo
iRounak wrote:
The only thing which is still buggin me is that it only seems to search for the exact query.

No, that is not true.
The search query "Paris" Matches “Paris”, “paris”, “I love Paris”, “paris-france.jpg”, and hopefully also “Comparison”.


Ptujec, just remove the line "set thequery to "pwd"". iRounak uses it only for test purpose. Then you will get the results according to your "thequery" set in LB search box.

Re: Adding spotlight tags?

Posted: Wed Dec 09, 2009 10:52 am
by ptujec
edo wrote:... just remove the line "set thequery to "pwd"". iRounak uses it only for test purpose. ...

I'm stupid, but not that stupid ;)

iRounak wrote:That calls for a different script which will take the words "file" and "test" as two separate queries ...


You are right. So this is what I put together with your information and the help of a friend.

Re: Adding spotlight tags?

Posted: Wed Dec 09, 2009 2:31 pm
by edo
ptujec wrote:
edo wrote:... just remove the line "set thequery to "pwd"". iRounak uses it only for test purpose. ...

I'm stupid, but not that stupid ;)


Sorry for the stupid impression I got from not that stupid question of yours :P

Re: Adding spotlight tags?

Posted: Wed Dec 09, 2009 2:37 pm
by edo
Is there any way to exclude some folder or even filetype from the search?
Usually I get many .mozeml files (Thunderbird) when searching for names (kMDItemDisplayName).

Re: Adding spotlight tags?

Posted: Wed Dec 09, 2009 2:56 pm
by ptujec
edo wrote:Is there any way to exclude some folder ...

I don't know if its possible in the script but its possible in the Spotlight Preferences.

Re: Adding spotlight tags?

Posted: Wed Dec 09, 2009 3:01 pm
by edo
ptujec wrote:
edo wrote:Is there any way to exclude some folder ...

I don't know if its possible in the script but its possible in the Spotlight Preferences.


I mean in scripts coz I cannot disable it in Spotlight since I need mozemls in Yep, Leap, HoudahSpot etc...

Re: Adding spotlight tags?

Posted: Wed Dec 09, 2009 3:06 pm
by ptujec
edo wrote: I mean in scripts coz I cannot disable it in Spotlight since I need mozemls in Yep, Leap, HoudahSpot etc...

Maybe you can find a hint in some of the resources I mentioned in the other entry:

ptujec wrote:... (Go here, here or here for background information.)

Re: Adding spotlight tags?

Posted: Wed Dec 09, 2009 3:29 pm
by iRounak
yes, ofcourse, there is a way to exclude.
replace "==" with "!="

Re: Adding spotlight tags?

Posted: Wed Dec 09, 2009 3:38 pm
by iRounak
To elaborate:
For excluding filetypes and such metadata use "!=" instead of "==".
Example:

Code: Select all

set thequery to "pwd"
set thecmd to "mdfind  'kMDItemDisplayName == " & quote & thequery & "*" & quote & "wc" & " && kMDItemFinderComment != " & quote & thequery & "*" & quote & "wc'"
do shell script thecmd


To exclude folders use "grep -v"
Example:

Code: Select all

set thequery to "pwd"
set thecmd to "mdfind  'kMDItemDisplayName == " & quote & thequery & "*" & quote & "wc" & " && kMDItemFinderComment != " & quote & thequery & "*" & quote & "wc'"
do shell script thecmd & " | grep -v /System/Library"

Re: Adding spotlight tags?

Posted: Wed Dec 09, 2009 3:49 pm
by ptujec
iRounak wrote:yes, ofcourse, there is a way to exclude.
replace "==" with "!="


iRounak wrote:… To exclude folders use "grep -v" ...

Nice! Should have known that after reading all that stuff ;) ...

Re: Adding spotlight tags?

Posted: Wed Dec 09, 2009 4:06 pm
by edo
ptujec wrote:
iRounak wrote:yes, ofcourse, there is a way to exclude.
replace "==" with "!="


iRounak wrote:… To exclude folders use "grep -v" ...

Nice! Should have known that after reading all that stuff ;) ...


"grep -v" doesn't work for me.

As to filetypes, I can exclude metadata but how to exclude exact filetype "Thunderbird Mail Message" (com.mozilla.thunderbird.mozeml) ?