Adding spotlight tags?

Sharing and discussing custom actions for LaunchBar
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 4:25 pm

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

Thats false. It works for me and it means that it works for you. You may have made error in writing the script.

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


Code: Select all

kMDItemContentType != " & quote & "com.mozilla.thunderbird.mozeml" & quote

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

Re: Adding spotlight tags?

Post by edo » Wed Dec 09, 2009 6:24 pm

iRounak wrote:
"grep -v" doesn't work for me.

Thats false. It works for me and it means that it works for you. You may have made error in writing the script.


Script doesn't show any error but the results include the folder that should have been excluded.

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


Code: Select all

kMDItemContentType != " & quote & "com.mozilla.thunderbird.mozeml" & quote


Could you combine this with searching kMDItemDisplayName? I am not at home with scripts, obviously.
Thanks.

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 6:37 pm

Script doesn't show any error but the results include the folder that should have been excluded.

apparently, you specified the folder name after "grep -v". You should specify the path.
Bring the folder in LaunchBar. Press Tab. Bring up Terminal. Press return.
You will see the path to that folder after the word "cd ". Below, I have shown the path to "/System/Library/" folder.

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"

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 6:40 pm

Code: Select all

Could you combine this with searching kMDItemDisplayName? I am not at home with scripts, obviously.

I don't use Thunderbird. So I cannot test this:

Code: Select all

set thequery to "pwd"
set thecmd to "mdfind  'kMDItemDisplayName == " & quote & thequery & "*" & quote & "wc" & " && kMDItemContentType != " & quote & "com.mozilla.thunderbird.mozeml" & quote & "'"
do shell script thecmd & " | grep -v /System/Library"

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

Re: Adding spotlight tags?

Post by edo » Wed Dec 09, 2009 6:48 pm

iRounak wrote:
Script doesn't show any error but the results include the folder that should have been excluded.

apparently, you specified the folder name after "grep -v". You should specify the path.
Bring the folder in LaunchBar. Press Tab. Bring up Terminal. Press return.
You will see the path to that folder after the word "cd ". Below, I have shown the path to "/System/Library/" folder.

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"


I did exactly as you put it and it fails.

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

Re: Adding spotlight tags?

Post by edo » Wed Dec 09, 2009 6:52 pm

iRounak wrote:

Code: Select all

Could you combine this with searching kMDItemDisplayName? I am not at home with scripts, obviously.

I don't use Thunderbird. So I cannot test this:

Code: Select all

set thecmd to "mdfind  'kMDItemDisplayName == " & quote & thequery & "*" & quote & "wc" & " && kMDItemContentType != " & quote & "com.mozilla.thunderbird.mozeml" & quote & "'"


Works perfectly. Thanks :)

Jono
Rank 4
Rank 4
Posts: 161
Joined: Mon Feb 25, 2008 11:25 am
Location: UK
Contact:

Re: Adding spotlight tags?

Post by Jono » Mon Mar 21, 2011 1:12 am

iRounak wrote:And how about searching the tags/comments:
Bring this script in LaunchBar, press space, type search query and press return.

Code: Select all

on handle_string(thequery)
   try
      tell application "LaunchBar" to hide
      set thecmd to "mdfind   'kMDItemFinderComment == " & quote & thequery & "*" & quote & "wc'"
      set theresult to do shell script thecmd
      set thelist to {}
      set allparas to every paragraph in theresult
      repeat with apara in allparas
         set end of thelist to (POSIX file apara) as alias
      end repeat
      if thelist is {} then set thelist to "No items were found"
      tell application "LaunchBar"
         set selection to thelist
         activate
      end tell
   on error e
      tell me to activate
      display dialog e
   end try
end handle_string

Thanks a lot, this is really helpful.

Post Reply