Forum: Ruby Run a Ruby script (.rbw) from a dock shortcut in Mac OS X (Leopard)?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2009-03-21 13:50
(Received via mailing list)
I can't seem to find out how to do this...  Thanks for any help.

I have Ruby installed on my Mac (OS X Leopard) and it works fine from
the terminal window.  I'd like to create a dock shortcut or be able to
just double-click the .rbw file to run it.  When I click it, it just
brings up a window that shows the code rather than running it.

Is there a way to put a shortcut down in the dock so I can just click
it to run the particular Ruby script (or click it from within
Finder)?

Thanks.
Tim H. (Guest)
on 2009-03-21 15:54
(Received via mailing list)
removed_email_address@domain.invalid wrote:
>
> Thanks.
>
>

 From the Finder, right-click and choose Get Info. On the Get Info
window, use Open with to associate .rb files with ruby. Use Change
All... to associate ruby with all .rb files.
Torli B. (Guest)
on 2009-03-21 18:32
Tim H. wrote:

>  From the Finder, right-click and choose Get Info. On the Get Info
> window, use Open with to associate .rb files with ruby. Use Change
> All... to associate ruby with all .rb files.

This looks fine, except you will not find ruby from within the "Choose
Other Application" window!? Tim, could you tell us how exactly did you
find Ruby there.

Thank you in advance.
Torli
matt neuburg (Guest)
on 2009-03-21 19:05
(Received via mailing list)
<removed_email_address@domain.invalid> wrote:

> I have Ruby installed on my Mac (OS X Leopard) and it works fine from
> the terminal window.  I'd like to create a dock shortcut or be able to
> just double-click the .rbw file to run it.  When I click it, it just
> brings up a window that shows the code rather than running it.

Try FastScripts Lite. It's free and gives you a menu of scripts, and you
can assign each script a keyboard shortcut. m.
Tim H. (Guest)
on 2009-03-22 00:29
(Received via mailing list)
Torli B. wrote:
> Thank you in advance.
> Torli

Well, rats. I can find ruby but OS X doesn't think it qualifies as an
"Application".

I suppose you could do something with Automator, but every time I start
up Automator it makes me want to scream :-(
Vince A. (Guest)
on 2009-03-22 01:59
unknown wrote:
> Is there a way to put a shortcut down in the dock so I can just click
> it to run the particular Ruby script (or click it from within
> Finder)?
>
> Thanks.

You should save the file as a Ruby file, but it must be made
'executable' to run as a script and not open in Terminal. To do this in
terminal you need to use:

chmod 755 /path/to/your/file

This will keep it from opening in Terminal. But it won't be an
application, so I don't think you can put it in the dock where you want
it.

If you want an Application which you can put on the dock, then you will
need to wrap your script using Platypus
(http://www.sveinbjorn.org/platypus). Platypus can take ruby (and other
script langs) and create double clickable applications from them.

You can also save your script with a unique prefix and name which will
allow you to use Spotlight to run it. For example, save your script as
xxMyScript.rb and you can access it relatively quickly using Spotlight
in 10.5 (much slower and different key combinations on Tiger):

1) type cmd-spacebar to set focus to spotlight search field
2) type 'xx.MyS' and wait a sec for it to appear in the "Top Hit" of the
Spotlight search results
3) type return when you see it as the "Top Hit" and it will launch and
run.

hth

vince
unknown (Guest)
on 2009-03-22 10:30
(Received via mailing list)
Thanks everyone.  I'll give these a try.
Louis-Philippe (Guest)
on 2009-03-23 16:54
(Received via mailing list)
Well, rats. I can find ruby but OS X doesn't think it qualifies as an
"Application".
Well, it doesn't need to, the Terminal is an application, so given you
put a
shebang line on top of your program and make your file executable it
could
work... if you want to go arround having to change the file association
for
ruby files, change the extension to .command and it will open up and
execute
in the terminal.

this only solves half of the problem though, you can click it, but still
can't put it in the dock.

L-P
2009/3/22 <removed_email_address@domain.invalid>
Louis-Philippe (Guest)
on 2009-03-23 17:13
(Received via mailing list)
ok, here is two quick options, both have limitations but they work to
some
point:

if you don't need a terminal output for your app, create a folder
hierarchy
around it to make it a ruby app like this:
appname.rb.app/Contents/MacOS/your_excutable_script.rb

the .rb.app seems to be the important detail not to forget in here.

or, if you need a terminal display for your app, you can always drop
your
.command (a said in my previous answer) in the document part of your
dock
(if you are on Leopard) and then clicking it will open a terminal and
run
it.

L-P

2009/3/23 Louis-Philippe <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.