How to open a specific webpage in system's default browser?

Hi everyone,

I’d like to know if I could open a specific webpage by running the system’s default browser, exactly how Rhino’s “Help” command does.

I know that a Rhino script like:

_Run Chrome.exe

will run Chrome, but it might have several issues:

  1. I couldn’t get a URL to work, tried a few things. just got the browser to launch.
  2. It might not be the system’s default browser.
  3. I’m not sure that command could work cross-platform.

If this is not achievable in Rhino script I could also write a plugin and run the plugin’s command.
opening a URL in the default browser in windows should be easy, but then I’ll have to make sure it will somehow work for Mac as well.

Thanks for your help :slight_smile:

Roy.


Edit: as for my question, Graham’s answer below answers it, but eventually I went on to run the python script through my plugin, details below as well.


Hello,

You can do this with a python script:

import webbrowser
webbrowser.open(r"https://discourse.mcneel.com/t/how-to-open-a-specific-webpage-in-systems-default-browser/109699")

Thanks for the quick reply and the answer.

It does work but now I wonder if there’s a way I could run that python script inside a plugin.

Yes probably, but would a simple RunPythonScript command be OK?

-_RunPythonScript "import webbrowser;webbrowser.open(r'https://discourse.mcneel.com/t/how-to-open-a-specific-webpage-in-systems-default-browser/109699/3')"

Thank you Graham,

That is the solution to the question I’ve asked and I guess that as a python script it would work cross platform, but actually my requirement has changed a little and I would like to show some information before I’d like to open the webpage.

So I do wish to know how and if it is possible to run a python script from my plugin.

Yes, see the PythonScript class in RhinoCommon

Thank you Steve.

If it would ever help anyone else:

PythonScript ps = PythonScript.Create();
ps.ExecuteScript(“import webbrowser; webbrowser.open(‘http://rhino3d.com’)”);

Plus you have a typo on this page and on this page, they say “localilation” :slight_smile:

1 Like