Designing Launchbar 6 Ruby Actions

Sharing and discussing custom actions for LaunchBar
Post Reply
beerich
Rank 4
Rank 4
Posts: 161
Joined: Thu Apr 05, 2007 11:05 am
Location: Toronto

Designing Launchbar 6 Ruby Actions

Post by beerich » Tue Nov 04, 2014 1:50 pm

Hi folks.

Trying out some nifty low hanging fruit type actions for Launchbar 6. Integration of Ruby into a proper Launchbar 6 Action is a bit fuzzy for me. So I have some questions:

  • If a script trips over a gem that's not installed, does "require 'rubygems'" auto-install them? I just see some requirements tripping all of this up. I'm not sure if it throws a smart error or handles it by using this other gem.
  • How can I pass a SINGLE parameter to a Ruby script?
  • How can I pass MULTIPLE parameters to a Ruby script? Can I just suggest delimiting with a "/" and parsing it in the script? Is that wise in this instance, given the apparent limitations?
  • Edited Extra: How can I handle launching a Ruby script that might or might not take an argument?

Any examples of these out there? I downloaded the examples posted by Obdev, and they're proving somewhat useful.

Cheers

BTW Ordered lists don't work in preview here in the forum post page...that I could get to work at least.

hlissner
Rank 2
Rank 2
Posts: 42
Joined: Mon Jun 16, 2014 6:06 am
Location: Toronto, ON
Contact:

Re: Designing Launchbar 6 Ruby Actions

Post by hlissner » Wed Nov 19, 2014 7:57 am

Oh hey, a fellow Torontonian!

beerich wrote:...does "require 'rubygems'" auto-install them...

No. If a gem isn't installed, with or without 'require "rubygems"', ruby will throw a LoadError. All it does is alter your ruby loadpath to load gems installed via the gem CLI tool. Plus, it's superfluous for ruby 1.9+ (it's done implicitly).

beerich wrote:...SINGLE/MULTIPLE parameters...

Whether there's 1 or N parameters, Ruby stores them in ARGV as a list of strings. You can tell LB6 what inputs the action accepts (strings or file paths) in the Info.plist file (more info here -- see "LBAcceptedArgumentTypes").

beerich wrote:...How can I handle launching a Ruby script that might or might not take an argument?...

Perhaps you'd check if ARGV.length > 0, then handle accordingly?

There are examples of a ruby script action in the action programming guide in the LB docs.

Hope that helps!

beerich
Rank 4
Rank 4
Posts: 161
Joined: Thu Apr 05, 2007 11:05 am
Location: Toronto

Re: Designing Launchbar 6 Ruby Actions

Post by beerich » Tue Dec 02, 2014 11:35 am

Hi there. Thanks for the reply. I'm frozen up at 4am clearing out my email. Heh.

Yeah I'm past 1.9.

OK, parsing the incoming string arguments (action params as I know them) is fairly straight forward. So do I have to copy the whole package and edit all this inside XCode?

Thanks for walking me through this. This is a bit outside of my scope.

Cheers

hlissner
Rank 2
Rank 2
Posts: 42
Joined: Mon Jun 16, 2014 6:06 am
Location: Toronto, ON
Contact:

Re: Designing Launchbar 6 Ruby Actions

Post by hlissner » Mon Dec 15, 2014 7:10 am

beerich wrote:Hi there. Thanks for the reply. I'm frozen up at 4am clearing out my email. Heh.

Yeah I'm past 1.9.

OK, parsing the incoming string arguments (action params as I know them) is fairly straight forward. So do I have to copy the whole package and edit all this inside XCode?

Thanks for walking me through this. This is a bit outside of my scope.

Cheers


Ack, didn't notice your reply! You can use whatever editor you like; which can be xcode if that's your preference. A lot of ruby programmers like to use Textmate. I'm an emacs/vim user myself. Communicating through these boards is proving a little difficult, so if you're still interested drop me a line at henrik at lissner dot net, and I'd be happy to walk you through it.

beerich
Rank 4
Rank 4
Posts: 161
Joined: Thu Apr 05, 2007 11:05 am
Location: Toronto

Re: Designing Launchbar 6 Ruby Actions

Post by beerich » Mon Dec 15, 2014 5:26 pm

OK, will do. Thank you, sir.

Post Reply