Context
I want to open a Firefox browser from the command line and have it go to youtube.com
I have tried:
open /Applications/Firefox.app --args -remote "openURL(www.youtube.com, new-tab)"
It successfully opens a Firefox, but does not navigate to youtube.com
Question:
How do I fix this?
open -a Firefox 'http://www.youtube.com/'
If firefox is your default browser you can simply use: open 'http://www.youtube.com'
Maybe you can append two aliases, edit ~/.bash_profile, append code below:
open_by_browser(){ open -a $1 $2}
alias firefox='open_by_browser firefox'
alias chrome='open_by_browser "Google Chrome"'
then you can open html file by Firefox
firefox xxx.html
or by Chrome
chrome xxx.html
The others' answers work by the way, but another way you can do it is:
/Applications/Firefox.app/Contents/MacOS/firefox "youtube.com"
You can open Firefox to a specific url and pass params if you want. Note: kiosk mode is an example only supported in Firefox 71 beta.
open -a /Applications/Firefox.app "https://stackoverflow.com" --args --kiosk
Related
I'm working on a small personal project and could not find an answer anywhere. I'm brand new to the Mac world and so have 0 experience with BSD. I'm just looking to make it so that when a condition in an if statement is met (I know how to do that part) my default browser (Firefox) will open up to a specified webpage (ex $var = stackoverflow, opens to stackoverflow.com)
Any help appreciated!
Other users have already intimated the use of the open command using the syntax:
open /Path/To/browser.app http://example.com
which, in the case of Firefox, would resemble something like this:
open /Applications/Firefox.app https://stackoverflow.com
However, you can simplify this somewhat using the -a flag, which allows you to simply specify the name of the application you wish to open, like so:
open -a Firefox https://stackoverflow.com
Furthermore, since Firefox is your default browser, you can omit the application altogether. URLs automatically get opened in the system's default browser:
open https://stackoverflow.com
which, in your case, will open the Stack Overflow website in Firefox, whilst on my system, it would open it up in Safari (my default browser).
You can also specify multiple URLs to open up multiple webpages at once:
open https://stackoverflow.com https://imdb.com https://youtube.com
which, on my system, opens each URL in a separate tab of the most recently active Safari window. On yours, it will do a similar thing using Firefox, depending whether you've set the browser to open new pages in a separate window, or as a new tab in the same window, etc.
Scripting
Combining this with your if...then control statement, a simple bash script might look something like this:
?URL() { [[ -z "${#}" ]] && return 1 \
|| printf '%s\n' "${#}" \
| egrep -ix 'stackoverflow|imdb|youtube' \
| printf 'https://%s.com\n' $(cat) \
| open $(cat); }
Then, running ?URL stackoverflow would open https://stackoverflow.com, whereas running ?URL stackoverflow dropbox imdb would open https://stackoverflow.com and https://imdb.com, but not https://dropbox.com (as it is not in the list of valid website matches).
Use the open command, followed by the path to your browser in single quotes, followed by the URL to the site you want to open in single quotes. example
open '/Applications/Google Chrome.app' 'http://youtube.com'
open '/Applications/Firefox.app/' 'http://www.du.ac.in'
You can see on the screenshot what the problem looks like. When I start chrome from Dock, the problem doesn't appear. The same problem in chronium.
Commands I used to start browser:
open /Applications/Google\ Chrome.app
open -a "Google Chrome"
open -a Google\ Chrome
macOS High Sierra 10.13.6
Google Chrome 67.0.3396.99
This has been discussed under this GitHub post found from a Google hit result Chrome shows no text when started by chromedriver #183.
Apparently they suggest something got broken in the most recent chrome-driver version of 2.40, their suggestion was so start Chrome with --disable-gpu set, which you can do from the terminal as below. The --disable-gpu apparently disables hardware acceleration using the GPU.
open -a Google\ Chrome --args --disable-gpu
or open it directly from the /Applications/
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --disable-gpu
An option is the following :
/usr/bin/open -a "/Applications/Google Chrome.app" 'http://google.com/'
Another alternative is to add it to bash.profile as follows:
Open ~/.bash_profile in your editor of choice.
Append this to the bottom of your ~/.bash_profile:
chrome () {
open -a "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome" "$1"
}
Save and close the file.
Run source ~/.bash_profile from the terminal to reload it.
Enjoy being able to type things like chrome http://google.com/ from the terminal.
We can also set Chrome as the default browser and execute the following command :
open http://google.com/
Does anyone know what's going on when I open up the new shell in MAC?
I checked my ~/.bash_profile, and I don't think there's problem.
Also, I set a alias of chrome="open -a 'Google Chrome'" for my project, but when I try to do the command, chrome index.html, under my project directory in terminal, it's just google's new page that pops up instead of my project page. I tested with other command such as open index.html, it works opening up Safari. But I need google Chrome page for my project.
You're missing the closing quote (') on line 7:
alias ls='ls -G'
# was missing -^
I'd like to use Terminal on Mac's open command to open a link to a page in Chrome's settings. Currently, I'm doing something like this:
alias chrome_settings='open -a "Google Chrome" chrome://settings/'
But I get a message stating The file /Users/codes/chrome:/settings does not exist.
How is it being interpreted as a file, when I intend for it to be opened as a web page? I've also tried passing it in as an argument, using open -a "Google Chrome" --args chrome://settings/, but this doesn't seem to work as well.
I'm quite new in .sh, I'm wonder how to open e.g.: Chrome web browser with two tabs, let's say that can be 'google.com' and 'yahoo.com'. So far I find out how to simply open 'Chrome' but I can't find how to force opening tabs in it.
I would be grateful if someone would gave me some hint.
On OS X, use the open CLI:
open -a 'Google Chrome' http://www.example.org http://google.com
Note that the protocol specifier (http://) is mandatory.