user2899498
user2899498

Reputation: 31

How to open a url through python code on mac osx

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.

Upvotes: 3

Views: 7878

Answers (1)

mathandy
mathandy

Reputation: 2010

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.

Upvotes: 5

Related Questions