Opening Chrome settings page in Terminal - macos

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.

Related

Open chrome from osx terminal with specific named tab target

I have implemented a file watcher that whenever a file is saved from a given watched folder it will open google chrome from the terminal like this /usr/bin/open -a "/Applications/Google Chrome.app" '${url}'
The problem is that If I save the file two times or more than one file, it will open many tabs in my chrome instance with the same url.
What I want to do is for it to refresh it instead. Similar as what would happen when you do this will open in somenamedtab
Is there any way to run /usr/bin/open -a "/Applications/Google Chrome.app" '${url}' but specifying which named tab?

On macOS, how to open a new Chrome window instead of a new tab from terminal (i.e., Bash command)

I want to open a new Chrome window via a Bash command on macOS. I know how to do it via AppleScript like this way:
tell application "/Applications/Google Chrome.app"
make new window
activate
end tell
But how can I implement it using a simple bash command? Thanks.
Try this one open -na "Google Chrome" --args --new-window
-a: specify the application
-n: open a new instance
--args: all arguments following it will be passed to the opened application

Opening Google Chrome from terminal on macOS causes no text rendering in browser

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/

Defining a shortcut to open Chrome from the command line on MacOS

I'd like to open .html and .xml files from the command line using Google Chrome on a Mac. Usually I just used the open command, but for .xml files I've noticed that the default application is XCode, so I'd like to specify the application with the -a argument.
The following command works:
Kurts-MacBook-Pro:MacOS kurtpeek$ open -a "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" ~/Documents/Seattle/comparables.xml
Here I've enclosed the path to Google Chrome - which has spaces in it - in quotes. In order to make this easier to type in the future, I'd like to define an environment variable $chrome in by .bash_profile containing this path, which I did as follows:
export chrome="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
The echo command does print this out:
Kurts-MacBook-Pro:~ kurtpeek$ echo $chrome
/Applications/Google Chrome.app/Contents/MacOS/Google Chrome
However, if I try to rerun the open -a with this environment variable to specify the application, I get the following error:
Kurts-MacBook-Pro:~ kurtpeek$ open -a $chrome Documents/Seattle/comparables.xml
The files /Users/kurtpeek/Chrome.app/Contents/MacOS/Google and /Users/kurtpeek/Chrome do not exist.
Apparently, in this case, the Bash shell does not 'recognize' the quotation marks I put in the definition of chrome. How can I make this work?
Following Set environment variable with having space linux, this can be done by enclosing $chrome in quotes:
Kurts-MacBook-Pro:~ kurtpeek$ open -a "$chrome" Documents/Seattle/comparables.xml
Kurts-MacBook-Pro:~ kurtpeek$
and the XML document gets opened in Chrome:
Update
It would appear (from https://superuser.com/questions/157484/start-google-chrome-on-mac-with-command-line-switches/157486#157486) that the open command looks in the Applications directory by default. So it suffices to just pass "Google Chrome" as an -a argument:
Kurts-MacBook-Pro:~ kurtpeek$ open -a "Google Chrome" Documents/Seattle/comparables.xml
Kurts-MacBook-Pro:~ kurtpeek$

`open -a Chrome` returns `Unable to find application named Chrome`

I have Google Chrome installed on macOS. The file /Application/Google Chrome.app/Contents/Info.plist shows:
CFBundleIdentifier : com.google.Chrome
CFBundleName : Chrome.
I am able to launch Google Chrome with open -b com.google.Chrome. But 'open -a Chrome' returns Unable to find application named Chrome.
How can I launch Google Chrome, or another generic app, with the syntax open -a?
AFAIK with the -a option you need to use the full app name. So for Chrome, you have to use:
open -a "Google Chrome"
or
open -a "Google Chrome.app"
For other applications, e.g. Chromium, you need to use the value of the key CFBundleName, which you can find with:
$ grep CFBundleName /Applications/Chromium.app/Contents/Info.plist -A 1
<key>CFBundleName</key>
<string>Chromium</string>
The utility grep looks for lines with CFBundleName in the file in the second argument, and the flag -A 1 prints one line after the matching lines.
The answer is open -a "Google Chrome" as stated.
If someone like me is looking how to do it with open -a "Chrome" you can simply open finder go to applications and rename "Google Chrome" to only "Chrome". I dunno if this can have some serious implications for the program, I believe it shouldn't.

Resources