חיפוש בתמיכה

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Cannot open new tab from the command line on OS X

  • 19 תגובות
  • 3 have this problem
  • 223 views
  • תגובה אחרונה מאת AliceWyman

more options

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?

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?

פתרון נבחר

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>

Read this answer in context 👍 2

כל התגובות (19)

more options

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

more options

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)

more options

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

http://kb.mozillazine.org/Command_line_arguments

more options

Is Firefox already running?

Make sure that you aren't starting Firefox with the "-no-remote" command line switch.

more options

@ideato See screenshot

more options

@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.

more options

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

  1. Ensuring all Firefox is closed down.
  2. Next try opening Firefox from a command line in the ordinary way. Not specifying any profile. It should open as expected.
  3. Use the Troubleshhoting Information page button to confirm the profile in use.
    Use the Troubleshooting Information page to help fix Firefox issues
  4. 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.
  5. Did that work ?
more options

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.

more options

Hello, please try with one hyphen (-).

thank you

more options

I have, and it didn't work - see my response here https://support.mozilla.org/en-US/questions/1130718#answer-896420

more options

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

  1. Ensuring all Firefox is closed down.
  2. Next try opening Firefox from a command line in the ordinary way. Not specifying any profile. It should open as expected.
  3. Use the Troubleshhoting Information page button to confirm the profile in use.
    Use the Troubleshooting Information page to help fix Firefox issues
  4. 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.
  5. 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 ?
more options

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.

more options

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.

more options

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.

more options

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.

more options

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.

more options
more options

פתרון נבחר

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

more options

Thanks for posting the AppleScript you created that solved the problem, so that others can benefit.