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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With