I want to open a url through python code on mac osx. I am using safari. I tried webbrowser.open(url,new=1,autoraise=True)
, webbrowser.open(url)
, webbrowser.open_new(url)
, webbrowser.open_new_tab(url)
. Sometimes, a new tab will open, Sometimes it will not, if already four-five tabs are opened. I want to make it work on all browsers like safari, chrome etc.
Asked
Active
Viewed 7,145 times
3

user2899498
- 31
- 1
- 3
-
Have you tried the methods [outlined here](http://stackoverflow.com/a/6042407/1681480) to specify the browser? – beroe Oct 20 '13 at 07:08
-
yes, but I want to open a url by default browser. Suppose, chrome, mozilla is not installed, then it should work with safari. – user2899498 Oct 20 '13 at 07:41
-
The default is to use the default browser. I think you should post some code where you can reproduce "This one opens as expected" and "this one doesn't". It is impossible to debug when you say it works sometimes. The library is cross platform, so all the examples in the other questions where this has been asked should be relevant. According to one of them chrome will specifically wait until you close a tab that has been opened in this way. – beroe Oct 20 '13 at 07:52
1 Answers
5
To add something to the previous answer... I had the same question, but wanted to open a local (SVG) file in Google Chrome. The solution I found (here) was
if platform == "darwin": # check if on OSX
file_location = "file:///" + file_location
webbrowser.get().open(file_location, new=new)
This works for me on OSX 10.10.4.

mathandy
- 1,892
- 25
- 32