Page 1 of 3

[LB6 Action] Spotlight (Integrated) [UPDATED]

Posted: Sat Jun 28, 2014 1:14 pm
by nbjahan
Updated
Image
Search in Spotlight with LaunchBar 6 and show the results as a list.

Download: https://github.com/nbjahan/launchbar-spotlight/releases/latest
Repo: https://github.com/nbjahan/launchbar-spotlight

Searches Spotlight and displays the results. You can enter advanced queries:

Code: Select all

-onlyin ~ "kMDItemUserTags=='*' && kMDItemContentType=='*app*"


If you know the type of item you’re looking for, you can specify it when performing a search. To specify the type, add the text kind:<type of item> at the end of your search. For example, if you want to search for images of New York City, enter New York City kind:images. If you want to search for email messages that mention Anne Johnson, enter Anne Johnson kind:email.

New Features

- Single action (Hold ^ to search by name)
- Send folders to change the search path
- Suggest search in parent folders if not found
- Check for updates , ...

ImageImageImage

Re: [LB6 Action] Spotlight (Integrated)

Posted: Sat Jun 28, 2014 10:11 pm
by Jono
I've wanted Spotlight searches that would return results in LaunchBar for a long time. This is excellent, thanks!

If I wanted to created another action that searched for a specific kind every time and I would just enter the name would that be easy to do based on this? For example I'd create an action to search for only Photoshop documents (kind:photoshop) and I would just enter the name to search for.

Also would it be possible to create an action to search for a few different file extensions (e.g. .psd OR .ai OR .sketch) where I just enter the name to search for and it only search for documents with those file extensions?

Re: [LB6 Action] Spotlight (Integrated)

Posted: Sun Jun 29, 2014 10:50 am
by nbjahan
The script is updated please re-downoad:

- disabled debug logging
- better error handling


Hey Jono, glad you liked it.

I recommend creating new action with the following applescript:

Code: Select all

on handle_string(s)
   set s to "\"(kMDItemDisplayName=='" & s & "*'cdw)&&(kMDItemContentType=='com.adobe.illustrator.ai-image'||kMDItemContentType=='com.adobe.photoshop-image'||kMDItemContentType=='com.bohemiancoding.sketch.drawing')\""
   tell application "LaunchBar"
      perform action "Spotlight Search" with string s
      remain active
   end tell
end handle_string


I tried this with JS script and it doesn't work(LB 6.0.1 hangs), don't know if it's Launchbar bug or the script:

Code: Select all

function runWithString(str) {
  LaunchBar.performAction('Spotlight Search', "\"(kMDItemDisplayName=='"+str+"*'cdw)&&(kMDItemContentType=='com.adobe.illustrator.ai-image'||kMDItemContentType=='com.adobe.photoshop-image'||kMDItemContentType=='com.bohemiancoding.sketch.drawing')\"");
}

Re: [LB6 Action] Spotlight (Integrated)

Posted: Sun Jun 29, 2014 1:34 pm
by Jono
Thanks a lot for this :D

I tried the AppleScript to search for Photoshop, Illustrator or Sketch documents. It works great finding the results, but when searching it plays an error sound, not sure why. Here's the action I created with it if you want to take a look http://d.pr/f/KHei

One other thing. I tried to create a search that would only search for Photoshop documents in ~/Design/Clients/ I tried a few different variations based on your .sh script and also as an AppleScript but couldn't get it to work properly. What would be the best way to do that?

Thanks again!

Re: [LB6 Action] Spotlight (Integrated)

Posted: Sun Jun 29, 2014 2:20 pm
by nbjahan
Please change CFBundleIdentifier to something unique and try again.

to limit the search folder use -onlyin <PATH> like this:

Code: Select all

on handle_string(s)
   set s to "-onlyin ~ \"(kMDItemDisplayName=='" & s & "*'cdw)&&(kMDItemContentType=='com.adobe.illustrator.ai-image'||kMDItemContentType=='com.adobe.photoshop-image'||kMDItemContentType=='com.bohemiancoding.sketch.drawing')\""
   tell application "LaunchBar"
      perform action "Spotlight Search" with string s
      remain active
   end tell
end handle_string

Re: [LB6 Action] Spotlight (Integrated)

Posted: Sun Jun 29, 2014 2:25 pm
by iRounak
Any advantage of making those action bundles? What would simple applescript not achieve in this case?

Re: [LB6 Action] Spotlight (Integrated)

Posted: Sun Jun 29, 2014 3:51 pm
by Jono
nbjahan wrote:To limit the search folder use -onlyin <PATH> like this:

Great, thanks!


nbjahan wrote:Please change CFBundleIdentifier to something unique and try again.

I tried that but still get the error sound. Funnily enough if I run it a script instead of using it as an .lbaction I don't get the error sound. Maybe it's a problem/bug with LaunchBar?


iRounak wrote:Any advantage of making those action bundles? What would simple applescript not achieve in this case?

Just the fact that you can choose what icon you can use makes it look better to me.

Re: [LB6 Action] Spotlight (Integrated)

Posted: Sun Jun 29, 2014 3:58 pm
by iRounak
Just the fact that you can choose what icon you can use makes it look better to me.

You can open any image in Preview, press Cmd+C to copy

and then paste it in the area where you see the icon of the file in its "Get Info" window in Finder.
That way, you can change the icon.

Also, in the LaunchBar index, wherever the script file is present, you can rename it whatever you want and also remove the extension ".scpt". That way the file name does not change but what in LB you will see it just the way you want it.

Re: [LB6 Action] Spotlight (Integrated)

Posted: Sun Jun 29, 2014 4:29 pm
by Jono
Oh really? That's great, thanks :)

Re: [LB6 Action] Spotlight (Integrated)

Posted: Sun Jun 29, 2014 5:02 pm
by ptujec
Jono wrote:
iRounak wrote:Any advantage of making those action bundles? What would simple applescript not achieve in this case?

Just the fact that you can choose what icon you can use makes it look better to me.


The action also allows you to run stuff in the background (LBRunInBackground)

Re: [LB6 Action] Spotlight (Integrated)

Posted: Sun Jun 29, 2014 5:07 pm
by iRounak
As I wrote earlier:
What would simple applescript not achieve in this case?
Basically, i want to avoid the OP to go the trouble of navigating in the bundles unnecessarily getting into the complexities of plists for no good reason

Re: [LB6 Action] Spotlight (Integrated)

Posted: Sun Jun 29, 2014 6:15 pm
by ptujec
Ok, sorry. Well it helps if the action takes a bit longer. Because when its not running in the background it freezes the app for the time running.

Re: [LB6 Action] Spotlight (Integrated)

Posted: Sun Jun 29, 2014 9:16 pm
by nbjahan
iRounak wrote:Any advantage of making those action bundles? What would simple applescript not achieve in this case?
No, at least not for now.
Just experimenting with the new features.
I think we should have a simple applescript action that works with LB5

Re: [LB6 Action] Spotlight (Integrated)

Posted: Thu Jul 03, 2014 2:18 pm
by Jono
I've only just realised that with these actions/scripts when I hit Return on a search result to open it nothing happens (apart from hearing an error sound).

Does it open search results for anyone else?

Re: [LB6 Action] Spotlight (Integrated)

Posted: Fri Jul 04, 2014 4:39 am
by iRounak
I've only just realised that with these actions/scripts when I hit Return on a search result to open it nothing happens (apart from hearing an error sound).

Does it open search results for anyone else?

Guess you have screwed up the original scripts/actions.

Try fresh:
Spotlight Search By Folder Name

Code: Select all

on handle_string(thequery)
   try
      set thecmd to "mdfind  'kMDItemDisplayName == " & quote & thequery & "*" & quote & "wc" & " && (kMDItemKind == \"Folder\")'"
      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 for " & thequery
         tell application "LaunchBar"
            remain active
            set selection to thelist
         end tell
         exit repeat
      end if
      
      tell application "LaunchBar"
         remain active
         set selection to thelist
         if (count of thelist) is not 1 then
            tell application "System Events"
               tell process "LaunchBar"
                  keystroke space
               end tell
            end tell
         end if
      end tell
   on error e
      tell me to activate
      display dialog e
   end try
end handle_string