Page 1 of 1

Ruby scripts

Posted: Sun Dec 24, 2006 6:37 am
by AmberV
I am trying to get a Ruby script to run with LB and it refuses to acknowledge that it is a script. I have tried removing the ".rb" extension, as per a suggestion in this forum to remove the ".sh", but then it refers to it as a text file instead of a Ruby source document. Is there no way to do this? The only thing I could think of was wrapping each Ruby script in a shell script -- awfully clumsy. :)

Posted: Sun Dec 24, 2006 12:26 pm
by norbert
First, make sure that your script contains a proper shebang line:

Code: Select all

#!/usr/bin/ruby
puts 'Hello world'

Further, the script must have execute permissions set to make LaunchBar recognize it as a Unix executable file:

Code: Select all

chmod +x MyHelloWorldScript

Posted: Sun Dec 24, 2006 2:57 pm
by AmberV
Affirmative on both counts. The script runs fine when I run it in Terminal, for instance. So I tried making a test Ruby script with vi, from Terminal, and when I added it to LB, it came up as an executable! So I took at look at the meta-data for the misbehaving file, since all of its UNIX things were set proper, and noticed that it had a Type and Creator set (to TEXT and JESP, respectively). After removing those, it added to LB as an executable.

So, there you have either a bug, or something to write up in the docs. I suppose at this point I should mention that I am using 4.2b2.

Posted: Sun Dec 24, 2006 3:11 pm
by AmberV
I apologise for straying off of the topic in my own thread, but now that I have this working -- is there any way to pipe the results of an executed script into the clipboard, rather than running it in Terminal?

Posted: Sun Dec 24, 2006 7:54 pm
by yanokwa
pbcopy and pbpaste are what you want.

To dump a detailed directory list to the clipboard, just type:
ls -al | pbcopy

You can then paste the contents of the clipboard to somefile using pbpaste:
pbpaste > somefile

Source: http://www.macosxhints.com/article.php? ... 7221216167

Posted: Sun Dec 24, 2006 10:47 pm
by AmberV
Splendid! That is slightly more clumsy than pressing Opt-Return or something in LB, but it will certainly do. That's a great tip, and useful beyond LaunchBar. Thank you.

Edit: I put the necessary pipe into the Ruby script itself, now it automatically inserts the result in the clipboard.