Tips: LaunchBar

If you come up with a shell script that does your search (via mdfind) I can help you to get the LB input and to put the results out to LB. But not these days, too much work.

Hint: The input is explained in the post above. The output should contain the paths and be JSON-compatible. (I would use the jq JSON processor. You can get it via Homebrew.)

Have you already read thru the Action documentation?

OK, here is a very simple action, but I think it does what you asked for. No bells and whistles, no pretty output!

Search JXA Scripts.lbaction.zip (10.0 KB)

It shows only scripts with "JXA" in the name (case sensitive). You can enter a search string, if you don’t enter nothing it shows you all "JXA" scripts. The search is live-updated.

The search is limited to the $HOME folder. Change this in the script if you want to search everywhere.

Many thanks, Tom.

OK. I'll take a look at the script, and see if I can figure out how to:

  • Set the default folder to my "DEV" folder in my DropBox.
  • Support a Send Folder to allow search of specific folder.

@Tom, I think setting the default folder is easy enough.
But allowing for a Send Folder to use instead is not obvious to me. I looked at your script and the Spotlight Search script, but didn't see any good examples that I could use as a model. If you know of one, please let me know.

OK, here you go:

Search JXA Scripts-ver2.lbaction.zip (6.1 KB)

>>> Please read through the whole post to understand how it works.
‌

The JXA-Search action now has two “personas”:

####A. Search for a JXA script

This is exactly as with the old version: bring up the JXA-Search action, hit the Spacebar and enter your query.

B. Set search path

This is the new part.

  1. Select any folder where you want to limit your search to, e.g. “Scripts”

  2. Send the “Scripts” folder to the Action, as you know it from other Send actions:

  3. While the “Scripts” folder is selected hit the Send key (Tab)

  4. Type your abbreviation to bring up the JXA-Search action

  5. Once the JXA-Search action is selected hit the Return key (not the Spacebar!)

Now the “Scripts” folder is the new search path.

‌
Now, to actually perform a search in the “Scripts” folder, bring up the JXA-Search action again and hit the Spacebar to enter your query. (Like in step A.)

You may have noticed that, to fully enjoy the action, you must make use of the Spacebar and of the Return key. If your problem with the Return key still persists, then this might be an issue!

To understand what the Return key does and what the Spacebar does, please open the script (default.scpt). You find two explanatory comments there.


Unfortunately I haven’t found a way to do the two things in one step.

But you know the ⌘B hotkey, don’t you? ⌘B brings up the recently performed actions and items (a very useful hotkey!).

That means in our case: after you have set a new search folder, just hit ⌘B and the JXA-Search action will instantly be selected again and you can enter your query by hitting the Spacebar.


Default search path:

The default search path is set to $HOME. You can change the path in the script: just replace all instances of ${HOME} with the POSIX path of your preferred default search path.

Quickly reset a custom search path to the default path:

To restore your default search path it is not necessary to send the default folder to the action.

Just type /d into the query field.

You don’t even have to close/re-open the action, just wait a second for the live search to kick in, and the path will be reset to the default! (You’ll see a message when it happened.)

As soon as you see the message you can type a new search string to search in your default path.
‌

Have fun!

… and remember, ⌘B is your friend!

1 Like

Many thanks, Tom. It was very kind of you to make these requested changes.
I'll check it out, and will definitely read/study your entire post.

If you cannot parse my sometimes very clumsy wording, just ask :wink:

To better understand the used AppleScript handlers, and to get an overview of all available handlers, don’t miss to read the AppleScript section of LB’s Developer Reference.

LB has an extended support for JavaScript. I think this is good news for you, since you are working much with JavaScript for Automation.

From the docs:

Scripts for LaunchBar Actions written in JavaScript are interpreted differently from scripts written in other scripting languages. […] LaunchBar 6 can run JavaScript code directly by leveraging Apple’s JavaScriptCore framework. This allows for even deeper integration with LaunchBar and additional possibilities to interact with LaunchBar […]. For more information on these additions, read the JavaScript Reference.

So, maybe, writing the Action with JS could open more options… I don’t know. Have a look at it, you are the JS expert.

1 Like

Have you tried the Action? (The 2nd version.)

Is it useful for your purposes or – more important – was it helpful to better understand how scripts can interact with LB’s input and output?

Yep, thanks. Sorry for the late feedback.

I'm running into a usability issue, not related specifically to your custom Action.
If I have an JXA displayDialog in the script, I can't get it work like the AppleScript equivalent. It either:

  1. Doesn't show immediately, but shakes the Dock icon for LB.
  2. If it does show, it doesn't have keyboard focus.

So, until I can resolve that issue, I prefer to use other tools to launch JXA scripts (KM mostly).

OK, that’s another scope.

But, nonetheless, I hope it was (somewhat) useful for learning about the various handlers you can use to interact with LB. In fact, once you’ve understood how to do it, writing an action for LB is often (not always) easier than writing a macro for KM.

As a side note: The very convenient thing with LB is that you can real-time--edit your scripts, since they are not residing inside a XML doc. And you can use your LB Bash and Perl etc. scripts also as standalone scripts, since they just respond to the usual argv argument.

Tom, it was very useful. Thanks again.
I just got sidetracked by a practical issue.

Hello there!

I just started using LB and discovered how powerful it can be with a bit of quick learning.
There’s something I’d like to know if it’s possible to do, because I haven’t figured it out yet.

When I search for a file, for example, a file named “screencaptures,” and I want to select the last image screen capture I made that was saved in this folder, LB shows me a long list. This list starts with many folders, and the screencapture images are at the very bottom of the list—especially the most recent screencapture, which is at the very end.

My issue is that when navigating the list with the arrow keys, I can only move from top to bottom. There doesn’t seem to be any "warp mode" that would allow me to press the up arrow and jump immediately to the bottom of the list.
Is there a way to do that?

I also have a second question: I noticed that when you select a file and press COMMAND + arrow key (up or down), LB applies a color to the file and displays a number on the right.
I tried to guess what this is for, but I’m still unsure. The number seems to indicate the total number of elements that have been highlighted with a color. Is this some kind of tagging system? What can you do with it? Does it help you quickly find preferred elements?

By the way, when I search for an item in LB, why is the initial highlight color blue, and then, after pressing the spacebar or right arrow to enter a folder, the color changes to orange?

Thanks in advance!

[…] "warp mode" that would allow me to press the up arrow and jump immediately to the bottom of the list. Is there a way to do that?

It is true, it seems there isn't a way to do that. On the other hand, I never really needed that (until now :yum:). Probably because after the first times when I manually selected the item, LB learned. But of course, in the specific case of generally wanting to go to the bottom of a given list, this is of no help.

I noticed that when you select a file and press COMMAND + arrow key (up or down), LB applies a color to the file and displays a number on the right.

With the Cmd (or Shift) key you can make multiple selections (like in the Finder, or any app that understands the macOS-like selection system). I.e., Shift for contiguous selections, Cmd to add single items to a selection.

You can then send the selected files to wherever you want, e.g. to an action to process them, or copy/move/sym/hardlink the selected files to a destination, etc.

after pressing the spacebar or right arrow to enter a folder, the color changes to orange?

Guess it just indicates that you are now inside the thing.


PS: Oh, and welcome to the forum :grin:


Edit:

I just found out that you can use the fn-RighArrow (or End if you have an extended keyboard) to jump to the end of the list. Also Home (fn-Left) and PageUp/Down (fn-Up/Down) work.

Pretty obvious, unless you have only small keyboards, like me, and have almost forgotten about these fn-Arrow functions :roll_eyes:.

Thank you.
I just notice that after the last update of thunderbird, the instant sending in joined file not working anymore, so I downgraded thunderbird.
Have a nice new year.
Thank you very much.

I'm sure I succeed to instant send multiple attachments to thunderbird in one email last week, but now I can't find what I did to made that. When I select more than one file and instant send them to thunderbird, it opens a new mail window for each file I selected (1 attachement per mail). Do you know the tip to attach more than one file to a single email ?

Thank by advance.

I have no clue about Thunderbird, but I tried it with (Apple’s) Mail and the behavior seems to be inconsistent. Here are the results of a quick test:

  • If the sent files are of the same type, they are attached to a single new mail.
  • If types are different , they are sometimes attached to separate new mails (e.g. one zip and one pdf), and sometimes to the same new mail (e.g. one webarchive and one txt file). Maybe there are other patterns that play a role, as said it was just a quick test.

In all cases, the behavior is identical to the drag and drop behavior, i.e. dropping the files to the Mail icon in the dock results in the same behavior.

This makes sense because – as far as I know – LB’s Send File is actually meant to be the same as dropping the files to the recipient app; so, how the files are processed is up to the drag and drop handler of the receiving application, and not in the hands of LaunchBar (possibly they tweaked the behavior for certain apps, IDK).

Please check if this is also true for Thunderbird.

Thank you for these clarifications.

Another thing—I’ve been using the “Monocle” app, which was very handy for performing a direct web search using Command+R.

Is there a direct shortcut that can be used to perform a Google search with LaunchBar?

Currently, you have to bring up the bar, start typing “Google,” then press Enter before you can begin typing your search, which feels a bit cumbersome. It would be great to assign Google search to a direct shortcut. Is this possible?
Thanks by advance.

Not to my knowledge. LaunchBar is built around Abbreviations, not modifier key keyboard shortcuts.
LB uses some keyboard shortcuts, but these are for meta functions, like Shift-Cmd-I (Show in Index), Cmd-G (Get Finder selection), and so on.

An Abbreviation is a sequence of letters (or one letter) typed into the LB window, for example, TE for TextEdit, or GO or G for Google search. As LB learns from your habits, these abbreviations are dynamic, i.e. you establish them simply by using them (although you can also manually assign an Abbreviation). Check out the corresponding section of the LaunchBar Help.

So, LB’s way to get to a Google search would be this:

  1. In LB’s settings, make sure you have set up a modifer tap to invoke LB (for example single tap Command key). This is faster and more convenient than to use a combo shortcut like Cmd-Space or similar, especially if you use LB a lot.
  2. Train LB to recognize G as your Google Abbreviation (or assign G manually).

Now, all you have to do to invoke a Google search is: Tap the Command key > Type G > Press Spacebar.

This is one more keypress than the shortest possible modifier key keyboard shortcut (e.g. Cmd-R), but the advantage is that you don’t have to remember any key combo (except that G means Google) and that you don’t steal modifier key combos from other apps or the system.

If you prefer “traditional” modifier key shortcuts, I would recommend to try other apps, like KM, or Alfred, or Apple’s Shortcuts app, Services, etc.


Edit:

Instead of pressing the Spacebar, you can also just hold the last Abbreviation key. With this, you are down to exactly two keypresses: Tap Cmd > Type and hold G.

See Instant Open.

If you want to do searches, I highly recommend @griffman's excellent macro called quick web search. I use this macro many, many times a day. I have and use Lauchbar but was never able to make much use of it for web searching.

@raouldouglas, I just added Edits with pretty relevant information to two of my previous posts: