[LB6 Action] Spotlight (Integrated) [UPDATED]

Sharing and discussing custom actions for LaunchBar
nbjahan
Rank 1
Rank 1
Posts: 34
Joined: Sat Jun 28, 2014 1:06 pm

[LB6 Action] Spotlight (Integrated) [UPDATED]

Postby nbjahan » Sat Jun 28, 2014 1:14 pm

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
Last edited by nbjahan on Wed Jul 23, 2014 12:58 pm, edited 1 time in total.

Jono
Rank 3
Rank 3
Posts: 157
Joined: Mon Feb 25, 2008 11:25 am
Location: UK
Contact:

Re: [LB6 Action] Spotlight (Integrated)

Postby Jono » Sat Jun 28, 2014 10:11 pm

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?

nbjahan
Rank 1
Rank 1
Posts: 34
Joined: Sat Jun 28, 2014 1:06 pm

Re: [LB6 Action] Spotlight (Integrated)

Postby nbjahan » Sun Jun 29, 2014 10:50 am

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')\"");
}

Jono
Rank 3
Rank 3
Posts: 157
Joined: Mon Feb 25, 2008 11:25 am
Location: UK
Contact:

Re: [LB6 Action] Spotlight (Integrated)

Postby Jono » Sun Jun 29, 2014 1:34 pm

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!

nbjahan
Rank 1
Rank 1
Posts: 34
Joined: Sat Jun 28, 2014 1:06 pm

Re: [LB6 Action] Spotlight (Integrated)

Postby nbjahan » Sun Jun 29, 2014 2:20 pm

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

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

Re: [LB6 Action] Spotlight (Integrated)

Postby iRounak » Sun Jun 29, 2014 2:25 pm

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

Jono
Rank 3
Rank 3
Posts: 157
Joined: Mon Feb 25, 2008 11:25 am
Location: UK
Contact:

Re: [LB6 Action] Spotlight (Integrated)

Postby Jono » Sun Jun 29, 2014 3:51 pm

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.
Last edited by Jono on Sun Jun 29, 2014 4:00 pm, edited 1 time in total.

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

Re: [LB6 Action] Spotlight (Integrated)

Postby iRounak » Sun Jun 29, 2014 3:58 pm

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.

Jono
Rank 3
Rank 3
Posts: 157
Joined: Mon Feb 25, 2008 11:25 am
Location: UK
Contact:

Re: [LB6 Action] Spotlight (Integrated)

Postby Jono » Sun Jun 29, 2014 4:29 pm

Oh really? That's great, thanks :)

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

Re: [LB6 Action] Spotlight (Integrated)

Postby ptujec » Sun Jun 29, 2014 5:02 pm

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)

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

Re: [LB6 Action] Spotlight (Integrated)

Postby iRounak » Sun Jun 29, 2014 5:07 pm

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

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

Re: [LB6 Action] Spotlight (Integrated)

Postby ptujec » Sun Jun 29, 2014 6:15 pm

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.

nbjahan
Rank 1
Rank 1
Posts: 34
Joined: Sat Jun 28, 2014 1:06 pm

Re: [LB6 Action] Spotlight (Integrated)

Postby nbjahan » Sun Jun 29, 2014 9:16 pm

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

Jono
Rank 3
Rank 3
Posts: 157
Joined: Mon Feb 25, 2008 11:25 am
Location: UK
Contact:

Re: [LB6 Action] Spotlight (Integrated)

Postby Jono » Thu Jul 03, 2014 2:18 pm

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?

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

Re: [LB6 Action] Spotlight (Integrated)

Postby iRounak » Fri Jul 04, 2014 4:39 am

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


Return to “LaunchBar Actions”

Who is online

Users browsing this forum: No registered users and 2 guests

cron