Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't launch a web browser in OS X via "open_new"? (Works fine on windows)

Tags:

python

macos

The following program opens a browser and navigates to www.cnn.com on Windows, but in OS X nothing happens. I'm not sure why.

import webbrowser
webbrowser.open_new("www.cnn.com")

Any thoughts?

like image 900
Dejas Avatar asked Jan 19 '26 23:01

Dejas


1 Answers

You need to do:

import webbrowser
webbrowser.open_new("http://www.cnn.com")

On OS X, this is converted to the following shell command:

echo 'open location "http://www.cnn.com"' | osascript

For whatever reason, open location www.cnn.com does not work in osascript on OS X.

This was tested on OS X Lion.

like image 163
Bill Lynch Avatar answered Jan 22 '26 18:01

Bill Lynch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!