I think what I need here is to know which magic command-line or OSA script program to run to start up a URL in an existing Firefox browser, if one is running, or to also start up Firefox if it isn't. On Mac.
I'm testing a Python program (Crunchy Python) which sets up a web server then uses Firefox for the front end. It starts the web application with the following:
try:
client = webbrowser.get("firefox")
client.open(url)
return
except:
try:
client = webbrowser.get()
client.open(url)
return
except:
print('Please open %s in Firefox.' % url)
I have Safari on my Mac as the default, but I also have Firefox installed and running. The above code started the new URL (on localhost) in Safari. Crunchy does not work well in Safari. I want to see it in Firefox, since I do have Firefox. Under Python 2.5, 2.6, and 2.7 (from version control) I get this:
>>> import webbrowser
>>> webbrowser.get("firefox")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/webbrowser.py", line 46, in get
raise Error("could not locate runnable browser")
webbrowser.Error: could not locate runnable browser
Firefox is there. I tried using webbrowser.get("/Applications/Firefox.app/Contents/MacOS/firefox %s") which starts up a new instance of Firefox then complains that another instance of Firefox is already running.
I really would like webbrowser to open up the URL in an existing tab/window of Firefox, if it's already running, or in a new Firefox is not already running.
I looked at webbrowser.py and it looks like there is no 'firefox' support for MacOSX. That's okay, I can add that. But I don't know how to open the URL in Firefox in the way I want to.
Ideas? And for now, I can force Crunchy to give me the URL, which I can manually paste into Firefox.