Adding spotlight tags?

Sharing and discussing custom actions for LaunchBar
ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Re: Adding spotlight tags?

Post by ptujec » Tue Dec 08, 2009 5:08 pm

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

iRounak
Rank 4
Rank 4
Posts: 191
Joined: Fri Oct 23, 2009 7:11 pm
Contact:

Re: Adding spotlight tags?

Post by iRounak » Tue Dec 08, 2009 5:22 pm

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

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Re: Adding spotlight tags?

Post by ptujec » Tue Dec 08, 2009 8:05 pm

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?

iRounak
Rank 4
Rank 4
Posts: 191
Joined: Fri Oct 23, 2009 7:11 pm
Contact:

Re: Adding spotlight tags?

Post by iRounak » Wed Dec 09, 2009 3:44 am

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.)

edo
Posts: 12
Joined: Fri Dec 04, 2009 10:16 pm
Contact:

Re: Adding spotlight tags?

Post by edo » Wed Dec 09, 2009 10:28 am

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.

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Re: Adding spotlight tags?

Post by ptujec » Wed Dec 09, 2009 10:52 am

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.

edo
Posts: 12
Joined: Fri Dec 04, 2009 10:16 pm
Contact:

Re: Adding spotlight tags?

Post by edo » Wed Dec 09, 2009 2:31 pm

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

edo
Posts: 12
Joined: Fri Dec 04, 2009 10:16 pm
Contact:

Re: Adding spotlight tags?

Post by edo » Wed Dec 09, 2009 2:37 pm

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).

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Re: Adding spotlight tags?

Post by ptujec » Wed Dec 09, 2009 2:56 pm

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.

edo
Posts: 12
Joined: Fri Dec 04, 2009 10:16 pm
Contact:

Re: Adding spotlight tags?

Post by edo » Wed Dec 09, 2009 3:01 pm

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...

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Re: Adding spotlight tags?

Post by ptujec » Wed Dec 09, 2009 3:06 pm

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.)

iRounak
Rank 4
Rank 4
Posts: 191
Joined: Fri Oct 23, 2009 7:11 pm
Contact:

Re: Adding spotlight tags?

Post by iRounak » Wed Dec 09, 2009 3:29 pm

yes, ofcourse, there is a way to exclude.
replace "==" with "!="

iRounak
Rank 4
Rank 4
Posts: 191
Joined: Fri Oct 23, 2009 7:11 pm
Contact:

Re: Adding spotlight tags?

Post by iRounak » Wed Dec 09, 2009 3:38 pm

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"

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Re: Adding spotlight tags?

Post by ptujec » Wed Dec 09, 2009 3:49 pm

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 ;) ...

edo
Posts: 12
Joined: Fri Dec 04, 2009 10:16 pm
Contact:

Re: Adding spotlight tags?

Post by edo » Wed Dec 09, 2009 4:06 pm

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) ?

Post Reply