If you remove the --args it seems to work fine, since --args can only affect things on first launch (it changes what main gets called with)
If you remove the --args it seems to work fine, since --args can only affect things on first launch (it changes what main gets called with)
Actually for me, the command is not working with the "--args" being present so the command working for me is
/usr/bin/open -a "/Applications/Google Chrome.app" 'http://google.com/'
OS X version: 10.6.8
I have found two ways to open a URL on macOS via command line
1.
open https://google.com
on run argv
tell application "Safari"
open location item 1 of argv
activate
end tell
end run
osascript open-safari.applescript https://google.com
open location <theUrl>
Is Known by AppleScript and can open the url directly. The default browser will be triggered. No need to invoke Safari explicitly.
Its trying to open the files from the Desktop folder. Safari is in the Applications folder. From the top level / you should type open Applications/safari This works fine for me. cd up to / and do ls. The Application folder should show up. If not you are in the wrong directory.
All you need to do in Terminal, no matter what directory you're in, is use
open -a Safari
open -a Google\ Chrome
and optionally, add the URL afterwards if you want to open the Browser to the given URL
open -a Safari http://apple.com/
Just enter
open "http://www.google.com"
And it'll open it in your default browser
To have your OS X machine open the default browser to a specific page, you just have to type:
open http://example.com/
Simple as pie. The open command was introduced way back on the NeXT operating system, and in its modern incarnation, uses LaunchServices to determine the appropriate application to open the given file or URL.
A non-specific approach is:
osascript -e 'open location "file:///Users/me/index.html#my-anchor"'
Don't use the open command.
Google Chrome:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome "file:///Users/me/index.html#my-anchor"
Safari:
osascript -e 'tell application "Safari" to open location "file:///Users/me/index.html#my-anchor2"'
Assuming you’re using the default bash shell:
for fff in $(echo https://one.com/whatever http://two.com/something%20else )
do
open $fff
done
You don’t necessarily need the $(echo a b c) and could just paste in the words. You can also skip the multiple lines with two semicolons where needed to split the for loop:
for fff in a b c; do echo $fff; done
Just supply all of the URLs you want to open as arguments to a single open command:
open https://www.youtube.com/ https://en.wikipedia.org/wiki/Main_Page
The open command has been written to handle this.
The reason it doesn't work with && is that in shell syntax, && is a delimiter between different commands, not between arguments to the same command. So it was trying to run https://en.wikipedia.org/wiki/Main_Page as a separate command, which doesn't work.
More specifically, && runs the second command only if the first command succeeds. There are a number of command delimiters you can use with different meanings:
cmd1 ; cmd2 # Runs cmd1 and then cmd2 (just as though they were on different lines)
cmd1 & cmd2 # Runs cmd1 and cmd2 simultaneously, with cmd1 in the background
cmd1 | cmd2 # Runs cmd1 and cmd2 simultaneously, with cmd1's output piped to cmd2's input
cmd1 && cmd2 # Runs cmd1, and then if it succeeds runs cmd2
cmd1 || cmd2 # Runs cmd1, and then if it fails runs cmd2
Opening a New Terminal Interactively
As of Mac OS X Lion 10.7, Terminal has a “New Terminal at Folder” Service you can enable in:
System Preferences > Keyboard > Services > Files and Folders
With this Service you can open a new terminal by selecting a folder or file path in any application and choosing this Service in the contextual menu (Control-Click or Right-Click) or the Services submenu in the application menu.
It doesn’t support “file:” URLs, but you can select the path part of the URL “/Library/Fonts” and use the Service with that.
There is also a “New Terminal Tab at Folder” Service.
Opening a New Terminal Programmatically
If you need to open it from a command line or shell script, you can use the open command to tell Terminal to open a directory pathname or “file:” URL:
open -a Terminal file:///Library/Fonts
(This is equivalent to dragging a folder, file path or “file:” URL onto the Terminal application, which opens a new Terminal at that location.)
This works from the command line:
/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal /Users/ &
Where /Users/ is the directory you want to set the working directory to.
You should use AppleScript. open command is for general purpose only: it opens that file(s) with that application, nothing more. Here you can find the right way: Open a local html file with url params through applescript
Thanks Sylter! Final script below will open Safari with whatever is passed in
on run argv
tell application "Safari"
make new document with properties {URL: item 1 of argv}
end tell
end run
From: Terminal command to open URL's in default and non-default browser (which I don't think is a duplicate)
If you want to open Chrome to a specific URL, just run
google-chrome www.example.com
To open your default browser to a specific URL, run
xdg-open www.example.com
If you need to run Chrome and close the terminal window afterward, run
google-chrome http://www.google.com </dev/null >/dev/null 2>&1 & disown
>/dev/null 2>&1 will prevent messages from the browser to be outputted to the terminal's window; & will put the process into the background and disown will remove the job / process from the job list, preventing a SIGHUP signal to be propagated to it.
To do this with another browser simply replace google-chrome with that other browser's executable name.
sensible-browser seems to be the option you're looking for. This will run the web browser set as default on your system, you can also pass parameters on it in order to run the web browser and open the given website(s).
Usage:
In a terminal, drop the next and hit Return
sensible-browser
Passing parameters:
The next command will open youtube.com in your preferred web browser:
sensible-browser youtube.com
How to set my favorite web browser flavour from the terminal?
Simply drop the next command in a terminal, hit Return and choose wisely:
sudo update-alternatives --config x-www-browser
In the next example I am choosing luakit as my default browser. You can change your default web browser as many times as you wish.
geppettvs@T400:~$ sudo update-alternatives --config x-www-browser
There are 5 choices for the alternative x-www-browser (providing /usr/bin/x-www-browser).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/google-chrome-stable 200 auto mode
1 /usr/bin/firefox 40 manual mode
2 /usr/bin/google-chrome-stable 200 manual mode
3 /usr/bin/konqueror 30 manual mode
4 /usr/bin/luakit 10 manual mode
5 /usr/bin/xlinks2 69 manual mode
Press enter to keep the current choice[*], or type selection number: 4
update-alternatives: using /usr/bin/luakit to provide /usr/bin/x-www-browser (x-www-browser) in manual mode
Unattaching from terminal
If you wish to keep your web browser running just after you close your terminal, simply add an ampersand symbol at the end of your command:
sensible-browser [parameters] &
Good luck!