A quick Ruby hack to steal some OS X goodness

by Gregory Brown

I really like the open command on OS X, but I was too lazy to look for its Linux equivalent.

Actually, my solution probably took less time than sifting through a google search:

system(case ARGV[0]

when /\.pdf/


when /\.html/


when /\.(rb)|(pl)|(pm)/


end + " #{ARGV[0]}")

Anyone else have fun little hacks they want to share?


2008-06-05 16:11:49
Hello, this script can be easily exploited:
ruby ./yourscript.rb 'file.html && echo "evil" > /tmp/testfile'.
You should use system(case ... , ARGV[0]) instead.
If you are using gnome you can use the command "gnome-open" instead.

kind regards

2008-06-05 17:11:47

granted, but in that case maybe I'd just type:

$ echo "evil" > /tmp/testfile
$ open file.html

2008-06-05 17:13:51
I'd probably use File.extname so that things like file.tar.gz don't trip it up, but I like the idea. I'll probably go make my own for the next half hour instead of doing something more productive.
2008-06-05 17:17:13

Good idea. I mostly wrote it for when I'm typing it by hand, so I don't really care if it's robust, but it's interesting to see two holes already found.

2008-06-05 17:44:55
Spoiling the fun: libfile-mimeinfo-perl comes with mimeopen. mimeopen can also open file based on magic (-M switch).
Paul Betts
2008-06-05 17:49:21
man gnome-open
2008-06-05 17:54:03
It doesn't surprise me that gnome-open exists, but I'm an awesome user:

So let's just say that I feel something more minimal is better.

@hdh, thanks for letting me know about mimeopen.

2008-06-05 18:45:14
For the record, the cross-distro, cross-desktop Linux equivalent is xdg-open.
2008-06-06 00:39:18
for Linux, there's gnome-open and xdg-open (from the xdg-utils package in Debian)
2008-06-06 02:12:26
It can be better to write the whole path of your programs, not just the names, like /usr/bin/vim instead of vim.
Christian Neukirchen
2008-06-06 07:47:00
man 1 see
2008-06-06 22:21:30
gnome-open? xdg-open? When will Linux distros give more thought to usability? "open" is obvious and easy to remember. "xdg-open" is an abomination.
2008-06-07 03:19:37
Приветствую всех!
У меня такой вопрос,кто что интересное подскажет буду признателен.
Мы с друзьями собираемся поехать в круиз по просторам России и ближнего зарубежья месяца на два на своих машинах,но не как не можем согласовать маршрут,если у кого уже был опыт такого путешествия,может,что посоветуете.Девчонок с собой не берем,думаем,что во все городах России с этим не будет проблем,если у кого будут рекомендации и в вопросе отдыха с девушками тоже буду признателен.

С уважением Сеньчик

2008-06-07 03:26:40

On Linux `open' is already taken for another command: openvt. I usually alias open to gnome-open or something similar. Problem solved.

2008-06-08 07:29:50
There's a shell, yanno. And it's *already running*.
Gregory Brown
2008-06-08 09:27:12

And Ruby does a great job as a shell scripting language. I have all sorts of fun stuff in ~/bin.

2008-06-08 21:21:42

Quanto viene pagato mediamente un analista-programmatore a milano?

fra qualche mese dovrei andare a Londra; mi consigliate una carta prepagata da poter usare l?? con facilit???
Io ho gi?? unaw Postepay..ma dubito che funzioni!!!