Force a custom action to open a *specific application* for a certain item

Sharing and discussing custom actions for LaunchBar
Post Reply
Alberti82
Posts: 5
Joined: Thu Oct 23, 2014 4:33 pm

Force a custom action to open a *specific application* for a certain item

Post by Alberti82 » Sat Feb 24, 2018 2:26 pm

Hello everyone,

Recently I have much enjoyed programming a few actions for LaunchBar that show a list of recent files for apps that I used very often, but are not of a Cocoa type. These include: Microsoft Word 2016, PowerPoint 2016, Excel 2016, Mathematica, Matlab, Acrobat DC, Illustrator CC, Photoshop CC, Together, OneNote. My actions are written in Objective-C (see also image below).

Image

I am planning to share my actions in the future with the community. Everything works great except for a tiny detail, which is bugging me for several days. The simplest way to understand my problem is through a concrete case:

Imagine that my PDF file format is associated with Skim.app instead of Adobe Acrobat, but I want to see the recent files of Acrobat. My action show them correctly. However, when I click on any item, the item is open with my default PDF viewer, that is, Skim.app. Of course, the user (for now, I) could send the item to Adobe Acrobat instead of pressing enter. But this seems to me unnecessary complicated.

I am wondering if there is anything I can provide in the structure of items to force LaunchBar to open a certain path-type item with the application I desire. Below is an example of a typical item my actions are generating:

{
"title" : "manuscript.pdf",
"subtitle" : "\/Volumes\/Macintosh HD\/Users\/andrea\/Desktop",
"path" : "\/Volumes\/\/Macintosh HD\/Users\/andrea\/Desktop\/manuscript.pdf"
}

What else can I add to this item to achieve my goal? To be clear, I am not looking for a solution using URI-type of URL addresses, because I still want to show the list of items as path-type items. This is the default behavior for all recent files of Cocoa applications which LaunchBar per default offers.

I am very grateful to anyone who could help me with this issue.

Best,
Andrea
Attachments
OwnAlbertiAction.png

raguay
Rank 1
Rank 1
Posts: 33
Joined: Fri Jul 18, 2014 11:08 am

Re: Force a custom action to open a *specific application* for a certain item

Post by raguay » Mon Feb 26, 2018 3:48 am

The best way to do this is to launch it yourself in the script. When selecting an item, have the action launch it using

```
LaunchBar.execute("open -a <path to program> <file to open>");

```

Alberti82
Posts: 5
Joined: Thu Oct 23, 2014 4:33 pm

Re: Force a custom action to open a *specific application* for a certain item

Post by Alberti82 » Tue Feb 27, 2018 7:49 pm

raguay wrote:The best way to do this is to launch it yourself in the script. When selecting an item, have the action launch it using

LaunchBar.execute("open -a <path to program> <file to open>");



Could you please elaborate more? I know that LaunchBar can execute shell commands through LaunchBar.execute, including "open -a [...]". However, it is not clear to me how I can instruct LaunchBar to execute this line of code when a certain item is clicked by the user. As I mentioned in my post, I would like to keep the displayed items as "path items" and not like "action items". In the latter case, yes, it seems possible to proceed as you suggested. But then, in the case of an action, when the user further clicks on one of the items, useful information such as file size, file date, etc. is not shown. This is why I would like to keep them as "paths".

By the way, do you know how to perform LaunchBar.execute(...) in Objective-C actions? This should be probably a separate question, different from my original question. The only way I can imagine is to wrap my Objective-C action in some Javascript. This would be however a pity since it seems unnecessarily complicated.

Post Reply