Create new LB5 actions via AppleScript

General discussions about LaunchBar
Post Reply
Kicweed
Rank 1
Rank 1
Posts: 23
Joined: Sun Nov 09, 2008 3:25 am
Contact:

Create new LB5 actions via AppleScript

Post by Kicweed » Fri Dec 12, 2008 3:42 pm

Is it possible to create new actions for LB5 using AppleSript? I'm thinking along the lines of getting text input through LB5 like you already can with the Calculator or the iCal actions, processing it with a custom-built AS script or using AS to parse it and interact with an application.

That would allow LB5 to easily interact with a much greater number of applications, without the need to bake this functionality in the "official" LB5 application.

Examples of custom actions:
- Prepend or append text to a text file
- Post a Tweet or send an IM to a contact from your Address Book
- Run terminal commands (and get the result in the clipboard or presente it through a notification)
- Manipulate files through command line tools like head, tail, grep etc. (and also command line versions of applications like SubEthaEdit or BBEdit)
- Send direct input to applications (like you currently can with iCal), for example add/manipulate tasks in Omnifocus

Related to this, I think it would add great value to LB5 if there was an official repository for users to share their actions.

Edit for spelling mistakes

beejay
Rank 2
Rank 2
Posts: 54
Joined: Thu Dec 28, 2006 9:40 pm

Post by beejay » Fri Dec 12, 2008 4:51 pm

I'm not sure I'm with you - you can create any scripts you want, using Applescript, or other scripting languages, and trigger them with LB.

For instance, I have an Applescript that sends selected junk mail to Knujon. I select the junk in Mail, command-space kn return and Launchbar runs the Applescript, which picks up the selected items, and forwards them to the appropriate email.

So Launchbar can easily trigger scripts, or send items to scripts through the command line etc.

Or do you mean something else?

holigen
Posts: 1
Joined: Fri Dec 12, 2008 4:34 pm

Post by holigen » Fri Dec 12, 2008 5:10 pm

Yes, it is possible to create new actions using AppleScript. Just put your script files in ~/Library/Application Support/LaunchBar/Actions and they'll be indexed automatically.

In order to get text input for your AppleScript you need to define a handler called handle_string that will be called with the string as its argument. To get files in your AppleScript, just define an open handler in your script.

There should be an Append Text action already included in LaunchBar, but I can't find it in the latest beta.

You can already send an IM to a contact from your Address Book, just not directly. If you type in the screen name of your contact, LaunchBar will open a new chat window for your contact.

You can also add head, tail, and grep (or ack, which is much better) to your index (in the Unix Executables category) and run them like any other command, let LaunchBar type the command and then press space, and then type your arguments. Of course, you can wrap the commands in an AppleScript if you want to get their results passed to the clipboard or a dialog window.

The help function in LaunchBar is very good and you can access it from the gear menu (if you've disabled LaunchBar's dock icon).

sjk
Wizard
Wizard
Posts: 315
Joined: Thu Sep 13, 2007 9:46 pm
Location: Eugene
Contact:

Post by sjk » Fri Dec 12, 2008 8:40 pm

Such a helpful and informative first post here, holigen. :)

Dennis
Rank 3
Rank 3
Posts: 146
Joined: Mon Dec 10, 2007 7:47 pm
Location: California

Post by Dennis » Fri Dec 12, 2008 9:21 pm

holigen wrote:There should be an Append Text action already included in LaunchBar, but I can't find it in the latest beta.


Append Text appears in the contextual Action Menu when you have a text file on the bar. Just hit Control-Right Arrow to see the menu, or use the Command-Shift-A to access the command directly.

I don't think there's currently a "Prepend Text" command though.

holigen wrote:You can already send an IM to a contact from your Address Book, just not directly. If you type in the screen name of your contact, LaunchBar will open a new chat window for your contact.


If you have some text on the bar, it seems like you should be able to Tab-send it to an iChat contact from Address Book. When I do that, however, it just beeps.

Oh well, not sure if being able to send the text directly from LaunchBar really saves that much time. You might as well just open the iChat contact and type your message in iChat itself.

-Dennis

Post Reply