librelist archives

« back to archive

Default Browser

Default Browser

From:
Roger Lovelock
Date:
2010-08-14 @ 02:47
Hi All,
   Know that you're all busy getting Policeman together, so I don't mind 
waiting a while for replies to this ...
I am creating reports from my Shoes app by writing HTML to a local file 
and then opening it in my default browser from my app for viewing and/or 
printing. This is a quick and easy way I have found for writing simple, 
cross-platform reports from my data. 
   Two problems - I have not found a simple cross platform way of opening 
a file in the 'default' browser - you can do this with java using a 
library called 'something or other' desktop. It's easy if I stick to 
Windows - where I just use system("start rep.htm") - so I thought the 
other way of doing it might be to test for the operating system of the 
current system running the app and then execute whichever command is most 
appropriate for it (I'd only worry about Windows, OSX & Linux). Tried out 
testing this with RUBY_PLATFORM - but I just got i386-mingw32 - which I 
assume is the same in all copies of Shoes for all platforms.
   Any suggestions, alternative approaches etc much appreciated.
Regards,
  Roger

Re: [shoes] Default Browser

From:
Steve Klabnik
Date:
2010-08-14 @ 05:26
You can also use launchy: http://rubygems.org/gems/launchy

It handles all this stuff for you. :)

Re: [shoes] Default Browser

From:
Cecil Coupe
Date:
2010-08-14 @ 05:33
On Sat, 2010-08-14 at 01:26 -0400, Steve Klabnik wrote:
> You can also use launchy: http://rubygems.org/gems/launchy
> 
> It handles all this stuff for you. :)

Smile. LOL. I'm so down into the metal that I forget
"There's a gem for that" should be the first choice.



Re: [shoes] Default Browser

From:
Cecil Coupe
Date:
2010-08-14 @ 03:10
On Sat, 2010-08-14 at 12:47 +1000, Roger Lovelock wrote:
> Hi All,
>    Know that you're all busy getting Policeman together, so I don't
> mind waiting a while for replies to this ...
> I am creating reports from my Shoes app by writing HTML to a local
> file and then opening it in my default browser from my app for viewing
> and/or printing. This is a quick and easy way I have found for writing
> simple, cross-platform reports from my data. 
>    Two problems - I have not found a simple cross platform way of
> opening a file in the 'default' browser - you can do this with java
> using a library called 'something or other' desktop. It's easy if I
> stick to Windows - where I just use system("start rep.htm") - so I
> thought the other way of doing it might be to test for the operating
> system of the current system running the app and then execute
> whichever command is most appropriate for it (I'd only worry about
> Windows, OSX & Linux). Tried out testing this with RUBY_PLATFORM - but
> I just got i386-mingw32 - which I assume is the same in all copies of
> Shoes for all platforms.
>    Any suggestions, alternative approaches etc much appreciated.

Roger,
  It's kind of obvious when you think about it, that RUBY_PLATFORM only
displays the platform you are running on. It faithfully reported your
platform. On my system,


> ccoupe@twb:~$ irb
> irb(main):001:0> RUBY_PLATFORM
> => "x86_64-linux"

It would be something different for a 32 bit linux. And somehing different
for the flavors of OSX.

  Assuming you have a case RUBY_PLATFROM statement with when cases that
use regexps to match, then Linux needs to call 'gnome-open
<your.html.file>', I can't speak for recent OSX but it used to be 'open
<your.html.file>'

> Regards,
>   Roger

Re: [shoes] Default Browser

From:
Devyn Cairns
Date:
2010-08-14 @ 05:11
On Fri, Aug 13, 2010 at 8:10 PM, Cecil Coupe <ccoupe@cableone.net> wrote:

> On Sat, 2010-08-14 at 12:47 +1000, Roger Lovelock wrote:
> > Hi All,
> >    Know that you're all busy getting Policeman together, so I don't
> > mind waiting a while for replies to this ...
> > I am creating reports from my Shoes app by writing HTML to a local
> > file and then opening it in my default browser from my app for viewing
> > and/or printing. This is a quick and easy way I have found for writing
> > simple, cross-platform reports from my data.
> >    Two problems - I have not found a simple cross platform way of
> > opening a file in the 'default' browser - you can do this with java
> > using a library called 'something or other' desktop. It's easy if I
> > stick to Windows - where I just use system("start rep.htm") - so I
> > thought the other way of doing it might be to test for the operating
> > system of the current system running the app and then execute
> > whichever command is most appropriate for it (I'd only worry about
> > Windows, OSX & Linux). Tried out testing this with RUBY_PLATFORM - but
> > I just got i386-mingw32 - which I assume is the same in all copies of
> > Shoes for all platforms.
> >    Any suggestions, alternative approaches etc much appreciated.
>
> Roger,
>  It's kind of obvious when you think about it, that RUBY_PLATFORM only
> displays the platform you are running on. It faithfully reported your
> platform. On my system,
>
>
> > ccoupe@twb:~$ irb
> > irb(main):001:0> RUBY_PLATFORM
> > => "x86_64-linux"
>
> It would be something different for a 32 bit linux. And somehing different
> for the flavors of OSX.
>
>  Assuming you have a case RUBY_PLATFROM statement with when cases that
> use regexps to match, then Linux needs to call 'gnome-open
> <your.html.file>'


xdg-open is far more universal.


> I can't speak for recent OSX but it used to be 'open
> <your.html.file>'
>

Still is.


>
> > Regards,
> >   Roger
>
>
>


-- 
    ~devyn

Re: [shoes] Default Browser

From:
Roger Lovelock
Date:
2010-08-14 @ 05:33
Thanks for the suggestions etc - much appreciated - I now have the 
following code :-

   if RUBY_PLATFORM =~ /(win|w)32$/ 
    system("start rep.htm")
   elseif RUBY_PLATFORM.downcase.include?("darwin")
    system("open","rep.htm")
   elseif RUBY_PLATFORM.downcase.include?("linux")
    system("xdg-open rep.htm")
   else
    alert("Report is in file rep.htm")
   end
Of course I only have a vista machine - so I can't test it fully - but 
it's a start!
Thanks
Roger


From: Devyn Cairns 
Sent: Saturday, August 14, 2010 3:11 PM
To: shoes@librelist.com 
Subject: Re: [shoes] Default Browser





On Fri, Aug 13, 2010 at 8:10 PM, Cecil Coupe <ccoupe@cableone.net> wrote:

  On Sat, 2010-08-14 at 12:47 +1000, Roger Lovelock wrote:
  > Hi All,
  > Â  Â Know that you're all busy getting Policeman together, so I don't
  > mind waiting a while for replies to this ...
  > I am creating reports from my Shoes app by writing HTML to a local
  > file and then opening it in my default browser from my app for viewing
  > and/or printing. This is a quick and easy way I have found for writing
  > simple, cross-platform reports from my data.
  > Â  Â Two problems - I have not found a simple cross platform way of
  > opening a file in the 'default' browser - you can do this with java
  > using a library called 'something or other' desktop. It's easy if I
  > stick to Windows - where I just use system("start rep.htm") - so I
  > thought the other way of doing it might be to test for the operating
  > system of the current system running the app and then execute
  > whichever command is most appropriate for it (I'd only worry about
  > Windows, OSX & Linux). Tried out testing this with RUBY_PLATFORM - but
  > I just got i386-mingw32 - which I assume is the same in all copies of
  > Shoes for all platforms.
  > Â  Â Any suggestions, alternative approaches etc much appreciated.


  Roger,
  Â It's kind of obvious when you think about it, that RUBY_PLATFORM only
  displays the platform you are running on. It faithfully reported your
  platform. On my system,


  > ccoupe@twb:~$ irb
  > irb(main):001:0> RUBY_PLATFORM
  > => "x86_64-linux"

  It would be something different for a 32 bit linux. And somehing different
  for the flavors of OSX.

  Â Assuming you have a case RUBY_PLATFROM statement with when cases that
  use regexps to match, then Linux needs to call 'gnome-open
  <your.html.file>'


xdg-open is far more universal.
 
  I can't speak for recent OSX but it used to be 'open
  <your.html.file>'



Still is.
 

  > Regards,
  > Â  Roger






-- 
    ~devyn

Re: [shoes] Default Browser

From:
Devyn Cairns
Date:
2010-08-14 @ 05:49
On Fri, Aug 13, 2010 at 10:33 PM, Roger Lovelock
<rogerlovelock@hotmail.com>wrote:

>  Thanks for the suggestions etc - much appreciated - I now have the
> following code :-
>
>    if RUBY_PLATFORM =~ /(win|w)32$/
>     system("start rep.htm")
>    elseif RUBY_PLATFORM.downcase.include?("darwin")
>     system("open","rep.htm")
>

Just wondering why you split the arguments here; you didn't for the others.
Nothing wrong with it, of course, they both work—but I always try to be
consistent.

   elseif RUBY_PLATFORM.downcase.include?("linux")
>     system("xdg-open rep.htm")
>    else
>     alert("Report is in file rep.htm")
>    end
> Of course I only have a vista machine - so I can't test it fully - but it's
> a start!
>

Looks fine. One comment about ".downcase.include?"… although this may be
clearer to non-rubyists, I would opt for a regexp. Shorter.

RUBY_PLATFORM =~ /w(in)?32$/i
RUBY_PLATFORM =~ /darwin$/i
RUBY_PLATFORM =~ /linux$/i


> Thanks
> Roger
>
>  *From:* Devyn Cairns <devyn.cairns@gmail.com>
> *Sent:* Saturday, August 14, 2010 3:11 PM
> *To:* shoes@librelist.com
> *Subject:* Re: [shoes] Default Browser
>
>
>
> On Fri, Aug 13, 2010 at 8:10 PM, Cecil Coupe <ccoupe@cableone.net> wrote:
>
>>  On Sat, 2010-08-14 at 12:47 +1000, Roger Lovelock wrote:
>> > Hi All,
>> > Â  Â Know that you're all busy getting Policeman together, so I don't
>>
>> > mind waiting a while for replies to this ...
>> > I am creating reports from my Shoes app by writing HTML to a local
>> > file and then opening it in my default browser from my app for viewing
>> > and/or printing. This is a quick and easy way I have found for writing
>> > simple, cross-platform reports from my data.
>> > Â  Â Two problems - I have not found a simple cross platform way of
>>
>> > opening a file in the 'default' browser - you can do this with java
>> > using a library called 'something or other' desktop. It's easy if I
>> > stick to Windows - where I just use system("start rep.htm") - so I
>> > thought the other way of doing it might be to test for the operating
>> > system of the current system running the app and then execute
>> > whichever command is most appropriate for it (I'd only worry about
>> > Windows, OSX & Linux). Tried out testing this with RUBY_PLATFORM - but
>> > I just got i386-mingw32 - which I assume is the same in all copies of
>> > Shoes for all platforms.
>> > Â  Â Any suggestions, alternative approaches etc much appreciated.
>>
>> Roger,
>> Â It's kind of obvious when you think about it, that RUBY_PLATFORM only
>>
>> displays the platform you are running on. It faithfully reported your
>> platform. On my system,
>>
>>
>> > ccoupe@twb:~$ irb
>> > irb(main):001:0> RUBY_PLATFORM
>> > => "x86_64-linux"
>>
>> It would be something different for a 32 bit linux. And somehing different
>> for the flavors of OSX.
>>
>> Â Assuming you have a case RUBY_PLATFROM statement with when cases that
>>
>> use regexps to match, then Linux needs to call 'gnome-open
>> <your.html.file>'
>>
>
> xdg-open is far more universal.
> Â
>
>> I can't speak for recent OSX but it used to be 'open
>> <your.html.file>'
>>
>
> Still is.
> Â
>
>>
>> > Regards,
>> > Â  Roger
>>
>>
>>
>
>
> --
> Â  Â  ~devyn
>



-- 
    ~devyn

Re: [shoes] Default Browser

From:
Roger Lovelock
Date:
2010-08-14 @ 06:00
Thanks - valid points - and useful learning for me!
Roger


From: Devyn Cairns 
Sent: Saturday, August 14, 2010 3:49 PM
To: shoes@librelist.com 
Subject: Re: [shoes] Default Browser





On Fri, Aug 13, 2010 at 10:33 PM, Roger Lovelock 
<rogerlovelock@hotmail.com> wrote:

  Thanks for the suggestions etc - much appreciated - I now have the 
following code :-

     if RUBY_PLATFORM =~ /(win|w)32$/ 
      system("start rep.htm")
     elseif RUBY_PLATFORM.downcase.include?("darwin")
      system("open","rep.htm")


Just wondering why you split the arguments here; you didn't for the 
others. Nothing wrong with it, of course, they both work—but I always try 
to be consistent.


     elseif RUBY_PLATFORM.downcase.include?("linux")
      system("xdg-open rep.htm")
     else
      alert("Report is in file rep.htm")
     end
  Of course I only have a vista machine - so I can't test it fully - but 
it's a start!


Looks fine. One comment about ".downcase.include?"… although this may be 
clearer to non-rubyists, I would opt for a regexp. Shorter.


RUBY_PLATFORM =~ /w(in)?32$/i
RUBY_PLATFORM =~ /darwin$/i
RUBY_PLATFORM =~ /linux$/i

  Thanks
  Roger


  From: Devyn Cairns 
  Sent: Saturday, August 14, 2010 3:11 PM
  To: shoes@librelist.com 
  Subject: Re: [shoes] Default Browser





  On Fri, Aug 13, 2010 at 8:10 PM, Cecil Coupe <ccoupe@cableone.net> wrote:

    On Sat, 2010-08-14 at 12:47 +1000, Roger Lovelock wrote:
    > Hi All,

    > Â  Â Know that you're all busy getting Policeman together, so I don't 

    > mind waiting a while for replies to this ...
    > I am creating reports from my Shoes app by writing HTML to a local
    > file and then opening it in my default browser from my app for viewing
    > and/or printing. This is a quick and easy way I have found for writing
    > simple, cross-platform reports from my data.

    > Â  Â Two problems - I have not found a simple cross platform way of 

    > opening a file in the 'default' browser - you can do this with java
    > using a library called 'something or other' desktop. It's easy if I
    > stick to Windows - where I just use system("start rep.htm") - so I
    > thought the other way of doing it might be to test for the operating
    > system of the current system running the app and then execute
    > whichever command is most appropriate for it (I'd only worry about
    > Windows, OSX & Linux). Tried out testing this with RUBY_PLATFORM - but
    > I just got i386-mingw32 - which I assume is the same in all copies of
    > Shoes for all platforms.

    > Â  Â Any suggestions, alternative approaches etc much appreciated.


    Roger,
    Â It's kind of obvious when you think about it, that RUBY_PLATFORM only 

    displays the platform you are running on. It faithfully reported your
    platform. On my system,


    > ccoupe@twb:~$ irb
    > irb(main):001:0> RUBY_PLATFORM
    > => "x86_64-linux"

    It would be something different for a 32 bit linux. And somehing different
    for the flavors of OSX.


    Â Assuming you have a case RUBY_PLATFROM statement with when cases that 

    use regexps to match, then Linux needs to call 'gnome-open
    <your.html.file>'


  xdg-open is far more universal.
  Â 
    I can't speak for recent OSX but it used to be 'open
    <your.html.file>'



  Still is.
  Â 

    > Regards,
    > Â  Roger






  -- 
  Â  Â  ~devyn




-- 
    ~devyn

Re: [shoes] Default Browser

From:
Roger Lovelock
Date:
2010-08-14 @ 03:16
Ta - of course - I'll dig further - thanks!

--------------------------------------------------
From: "Cecil Coupe" <ccoupe@cableone.net>
Sent: Saturday, August 14, 2010 1:10 PM
To: <shoes@librelist.com>
Subject: Re: [shoes] Default Browser

> On Sat, 2010-08-14 at 12:47 +1000, Roger Lovelock wrote:
>> Hi All,
>>    Know that you're all busy getting Policeman together, so I don't
>> mind waiting a while for replies to this ...
>> I am creating reports from my Shoes app by writing HTML to a local
>> file and then opening it in my default browser from my app for viewing
>> and/or printing. This is a quick and easy way I have found for writing
>> simple, cross-platform reports from my data.
>>    Two problems - I have not found a simple cross platform way of
>> opening a file in the 'default' browser - you can do this with java
>> using a library called 'something or other' desktop. It's easy if I
>> stick to Windows - where I just use system("start rep.htm") - so I
>> thought the other way of doing it might be to test for the operating
>> system of the current system running the app and then execute
>> whichever command is most appropriate for it (I'd only worry about
>> Windows, OSX & Linux). Tried out testing this with RUBY_PLATFORM - but
>> I just got i386-mingw32 - which I assume is the same in all copies of
>> Shoes for all platforms.
>>    Any suggestions, alternative approaches etc much appreciated.
>
> Roger,
>  It's kind of obvious when you think about it, that RUBY_PLATFORM only
> displays the platform you are running on. It faithfully reported your
> platform. On my system,
>
>
>> ccoupe@twb:~$ irb
>> irb(main):001:0> RUBY_PLATFORM
>> => "x86_64-linux"
>
> It would be something different for a 32 bit linux. And somehing different
> for the flavors of OSX.
>
>  Assuming you have a case RUBY_PLATFROM statement with when cases that
> use regexps to match, then Linux needs to call 'gnome-open
> <your.html.file>', I can't speak for recent OSX but it used to be 'open
> <your.html.file>'
>
>> Regards,
>>   Roger
>
>
>