Saturday, 24 November 2018

macos - How to open a new Firefox window with URL argument

I am trying to upgrade the existing answer


How to open a new Firefox window with Terminal


to accept a URL as an argument and open a NEW Firefox window.


I can use


open -a Firefox 'http://localhost:3000'

but it opens in a tab and not a NEW window as desired.


One variation is


open -n -a Firefox 'http://localhost:3000'

which gives me the standard error



Close Firefox, A copy of Firefox is already open. Only one copy of Firefox can be open at a time



BUT it opens the URL in my default browser Safari.




I have tried various options based on the man page for open and on the Mozilla site for opening URLs with their products but they say that the info is deprecated and may not work. It does not for me e.g.


/Applications/Firefox.app/Contents/MacOS/firefox -new-window "http://localhost:3000"
/Applications/Firefox.app/Contents/MacOS/firefox -remote "openURL(http://localhost:3000, new-window)"

both fail with the common error above.


I tried to modify the Script in the earlier link. I updated it to the following.


# A function to be able to open up a new Firefox window if firefox is already
# running.
function firefox-window() {
/usr/bin/env osascript <<-EOF
on run argv
tell application "System Events"
if (name of processes) contains "Firefox" then
tell application "Firefox" to activate
keystroke "n" using command down
else
tell application "Firefox" to activate
end if

return "I am trying to open " & item 1 of argv & " in a new Firefox window."
(*
if & item 1 of argv &
return "I am the if you seek"
tell application "Firefox" OpenURL & item 1 of argv &
end if
*)

end tell
end run
EOF
}

I get the error:



execution error: Can’t make item 1 of {} into type Unicode text. (-1700)



and I am stuck there. So I am getting a problem getting the URL into the applescript as an argument.


Well I get a host of other errors but the original script runs despite the ones before the UNICODE error.


~$ firefox-window 'http://localhost:3000'
2012-06-10 16:13:30.258 osascript[789:60f] Error loading /Library/ScriptingAdditions/Adobe Unit
Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit
Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find:
/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no
matching architecture in universal wrapper
osascript: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit
Types.osax" declares no loadable handlers.
294:300: execution error: Can’t make item 1 of {} into type Unicode text. (-1700)

I was hoping that this could be simple but it has me banging my head on the wall. I am mystified that it will not work with a simple open command so I can do it in a shell script.


Any help would be appreciated on getting Firefox to open a NEW window while passing a URL to it.

No comments:

Post a Comment

Where does Skype save my contact&#39;s avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...