Cannot open new tab from the command line on OS X
I want to be able to open a new tab in an existing window from the command line on Mac OS X. The help indicates that I should be able to do this by running:
/Applications/Firefox.app/Contents/MacOS/firefox-bin --new-tab <url>
but this attempts to open a second copy of the browser, which results in the error:
"A copy of Firefox is already open. Only one copy of Firefox can be open at a time."
Is there a way round this?
Seçilen çözüm
Just for completeness, I've created an AppleScript to do the job.
The script is:
on firefoxRunning() tell application "System Events" to (name of processes) contains "Firefox" end firefoxRunning
on run argv
if (firefoxRunning() = false) then do shell script "open -a Firefox " & (item 1 of argv) else tell application "Firefox" to activate
tell application "System Events" keystroke "t" using {command down} keystroke item 1 of argv & return end tell end if end run
You can run it from the command line as:
osascript ffnewtab.scpt <url>
Bu yanıtı konu içinde okuyun 👍 2Tüm Yanıtlar (19)
Hello, did you try without the -bin ?
/Applications/Firefox.app/Contents/MacOS/firefox -new-tab <url>
also, in your post you have two hypens (-) before the --new-tab, by mistake ?
thank you
Thanks for the suggestions. Sadly, no combination of one or two hyphens, or adding/removing the -bin has made any difference.
(Incidentally, the two hyphens is what's listed by firefox --help)
squaregoldfish said
(Incidentally, the two hyphens is what's listed by firefox --help)
where ?
https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options
Is Firefox already running?
Make sure that you aren't starting Firefox with the "-no-remote" command line switch.
@ideato See screenshot
@cor-el Yes, Firefox is already running (started from the Dock).
I've experimented with starting it from the command line, to make sure there's no hidden options being set in the Dock icon, and then trying to open a new tab. It makes no difference - I still get the same error.
I use Linux or Windows, so not the best person to answer Mac questions.
If you try opening Firefox from an icon or from a command line and you have NOT set -no-remote then Firefox should open a new tab or a new window. That is even without you explicitly trying to specify a new tab page. As explained in
Note that reminds us not to use -no-remote on the firefox profile used as the default browser.
I wonder if you have already created multiple profiles and multiple shortcuts. Try searching the whole computer for places.sqlite that is the bookmarks database and there will be one of those files in each and every Firefox profile.
Check your shortcuts, icons, or scripts to ensure they do not include -no-remote . (Sorry not sure how to do that on a Mac or what a Mac actually uses)
Try
- Ensuring all Firefox is closed down.
- Next try opening Firefox from a command line in the ordinary way. Not specifying any profile. It should open as expected.
- Use the Troubleshhoting Information page button to confirm the profile in use.
Use the Troubleshooting Information page to help fix Firefox issues - Now repeat the action again from the comandline. (Without shutting down the single Firefox preocess that is still running) That should result in a new tab or a new window opening. That should not produce an error message.
- Did that work ?
I only have one icon on the Dock, and that's the one that is provided by default when Firefox is installed. I have not made any changes to it, nor have I created any other links/shortcuts myself. I also only have one profile.
As I mentioned above, opening Firefox directly from the command line as you describe still produces the error.
Hello, please try with one hyphen (-).
thank you
I have, and it didn't work - see my response here https://support.mozilla.org/en-US/questions/1130718#answer-896420
squaregoldfish said
I only have one icon on the Dock, and that's the one that is provided by default when Firefox is installed. I have not made any changes to it, nor have I created any other links/shortcuts myself. I also only have one profile. As I mentioned above, opening Firefox directly from the command line as you describe still produces the error.
John99 said
Check your shortcuts, icons, or scripts to ensure they do not include -no-remote . (Sorry not sure how to do that on a Mac or what a Mac actually uses)
Try
- Ensuring all Firefox is closed down.
- Next try opening Firefox from a command line in the ordinary way. Not specifying any profile. It should open as expected.
- Use the Troubleshhoting Information page button to confirm the profile in use.
Use the Troubleshooting Information page to help fix Firefox issues- Now repeat the action again from the comandline. (Without shutting down the single Firefox preocess that is still running) That should result in a new tab or a new window opening. That should not produce an error message.
- Did that work ?
Thanks for the reply. I had hoped that would have worked. Can you give some more information about what actually happened please.
- What happened when you checked the shortcut.
- What does the shortcut use as its script or link ?
- At step 3 what profile did you find
- What is its full path ?
- And the full name of the profile folder?
- At step 4 what is the actual command you used ?
What happened when you checked the shortcut. What does the shortcut use as its script or link ?
The shortcut simply runs 'firefox'. It's bundled into an application package, so the path is internal. In my command line tests I've been running the same executable.
At step 3 what profile did you find What is its full path ? And the full name of the profile folder?
The full path of the profile folder is
/Users/<my_username>/Library/Application\ Support/Firefox/Profiles/r05eparo.default
It's the only profile on the machine.
At step 4 what is the actual command you used ?
/Applications/Firefox.app/Contents/MacOS/firefox
This is the path to the executable inside the application package. I can run it with the full path, or from the local directory with './firefox', and it gives the same results.
This is apparently a bug in Firefox on Mac OS X that will not be fixed. See: Bug 393645 - -new-tab command line parameter doesn't behave correctly or consistently in MacOSX.
What if you substitute -url for the -new-tab parameter?
With default settings (new window diverted to a new tab on the General panel of the Preferences page), this should add a new tab to the last active window.
Thanks Alice & Jeff, OS X does have similarities with Linux, but still has oddities where it differs. I will bookmark this and try and remember this quirk. squaregoldfish, Sorry for the unnecessary questions.
Alice, thanks for pointing out the bug report. Someone gave an AppleScript workaround there, so I'll have a play with that and see if I can get it working.
John99, don't worry about it - you were trying to help, and going through the standard checks is always worthwhile :)
And for completeness, jscher2000 - -url doesn't work either.
Thanks to everyone who tried to help.
Seçilen çözüm
Just for completeness, I've created an AppleScript to do the job.
The script is:
on firefoxRunning() tell application "System Events" to (name of processes) contains "Firefox" end firefoxRunning
on run argv
if (firefoxRunning() = false) then do shell script "open -a Firefox " & (item 1 of argv) else tell application "Firefox" to activate
tell application "System Events" keystroke "t" using {command down} keystroke item 1 of argv & return end tell end if end run
You can run it from the command line as:
osascript ffnewtab.scpt <url>
squaregoldfish tarafından
Thanks for posting the AppleScript you created that solved the problem, so that others can benefit.