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.
Related
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?
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'
I would like to open many of my programs through the mac terminal, since I use that frequently. For example, I want to be able to launch "chrome" from the Mac OSx terminal by typing open chrome.
Of course, this would only work if the environmental variable path knows where to find the executable file for this program. I've tried searching for the executable file for applications (such as chrome) using this:
find . -iname "*chrome*"
but none of the results work ( and there were a lot of results, of course). So, I'm wondering what is the best way to either
1) find the executable to add to the PATH environmental variable
or
2) launch an application via some other method
Thanks.
Generally as far as I've seen, you can launch practically any application like so:
# binary file:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
# open .app:
open /Applications/Google\ Chrome.app/
# binary + variable:
appName="Google Chrome"
"/Applications/$appName.app/Contents/MacOS/$appName"
# open + variable:
appName="Google Chrome"
open "/Applications/$appName.app/"
Hope this helps! :)
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
I have a program launching a website via the following command.
cmd "start /max http://url.com"
When launching a website via this method it uses the default browser with its default settings for opening a new window. for example, Firefox and IE will open the window inside the tab of an existing window if they are set to do so. I have reports of IE 6 replacing the content of a current opened window with the content of url.com. I've tested this and sure enough when IE 6 is set as the default browser and with a current webpage opened the above will replace the content of the opened window with url.com rather than opening a fresh window.
Upon running some tests I see the command listed here:
cmd "start /max iexplore.exe http://url.com"
will consistently open a new window( with Internet Explorer of course) regardless of an existing window being present or not.
Can anyone tell me if I'm missing a silly setting in IE 6 or if there is a way to duplicate the "always open a new window" functionality exhibited by calling iexplore.exe directly, but with calling the user default browser instead.
You can just use
explorer "https://google.com"
Which will launch your default browser and navigate to that site.
And on Mac I've using
open "https://google.com"
To open a URL with the default browser, you can execute:
rundll32 url.dll,FileProtocolHandler https://www.google.com
I had issues with URL parameters with the other solutions. However, this one seemed to work correctly.
start chrome https://www.google.com/ or start firefox https://www.google.com/
This worked for me:
explorer <YOUR URL>
For example:
explorer "https://www.google.com/"
This will open https://www.google.com/ in your default browser.
IE has a setting, located in Tools / Internet options / Advanced / Browsing, called Reuse windows for launching shortcuts, which is checked by default. For IE versions that support tabbed browsing, this option is relevant only when tab browsing is turned off (in fact, IE9 Beta explicitly mentions this). However, since IE6 does not have tabbed browsing, this option does affect opening URLs through the shell (as in your example).
You can start web pages using command line in any browser typing this command
cd %your chrome directory%
start /max http://google.com
save it as bat and run it :)
Working from VaLo's answer:
cd %directory to browser%
%browser's name to main executable (firefox, chrome, opera, etc.)% https://www.google.com
start https://www.google.com doesn't seem to work (at least in my environment)
Ok, The Windows 10 BatchFile is done works just like I had hoped. First press the windows key and R. Type mmc and Enter. In File Add SnapIn>Got to a specific Website and add it to the list. Press OK in the tab, and on the left side console root menu double click your site. Once it opens Add it to favourites. That should place it in C:\Users\user\AppData\Roaming\Microsoft\StartMenu\Programs\Windows Administrative Tools. I made a shortcut of this to a folder on the desktop. Right click the Shortcut and view the properties. In the Shortcut tab of the Properties click advanced and check the Run as Administrator. The Start in Location is also on the Shortcuts Tab you can add that to your batch file if you need. The Batch I made is as follows
#echo off
title Manage SiteEnviro
color 0a
:Clock
cls
echo Date:%date% Time:%time%
pause
cls
c:\WINDOWS\System32\netstat
c:\WINDOWS\System32\netstat -an
goto Greeting
:Greeting
cls
echo Open ShellSite
pause
cls
goto Manage SiteEnviro
:Manage SiteEnviro
"C:\Users\user\AppData\Roaming\Microsoft\Start Menu\Programs\Administrative Tools\YourCustomSavedMMC.msc"
You need to make a shortcut when you save this as a bat file and in the properties>shortcuts>advanced enable administrator access, can also set a keybind there and change the icon if you like. I probably did not need :Clock. The netstat commands can change to setting a hosted network or anything you want including nothing. Can Canscade websites in 1 mmc console and have more than 1 favourite added into the batch file.
Using a CLI, the easiest way (cross-platform) I've found is to use the NPM package https://github.com/sindresorhus/open-cli
npm install --global open-cli
Installing it globally allows running something like open-cli https://unlyed.github.io/next-right-now/.
You can also install it locally (e.g: in a project) and run npx open-cli https://unlyed.github.io/next-right-now/
Or, using a NPM script (which is how I actually use it):
"doc:online": "open-cli https://unlyed.github.io/next-right-now/",
Running yarn doc:online will open the webpage, and this works on any platform (windows, mac, linux).