use google-chrome to programatically open/refresh links in the browser from linux command line

1k Views Asked by At

when i am working from the command line, i often use some shortcuts to open links in google-chrome.

i do that for example with:

google-chrome "https://stackoverflow.com" "https://github.com"

now i have to things i like to solve:

  1. when google chrome isnt open yet: chrome will be launched with the link. This is fine, except the fact, that google-chrome automatically closes, when i close my terminal. How can I have it in the way, that chrome stays open, even when i close my terminal from where i launched chrome?

  2. when google-chrome is already open, i sometimes already have the link openened, which i then open in a second tab again. so i have the same link opened twice. This often happens, when i relaunch my tmux-session with tmuxinator QUESTION: how can i programatically check (for example with bash) if the link, the command tries to open, is already open? I want to do a refresh for that case.

Do you have any tipps for automating this, which tool i can best use for that? Maybe there is an api for google-chrome my code can talk to or is there some chrome app i can use for that?

Thank you in advance!

2

There are 2 best solutions below

0
On

From a long time, but:
"&" is to free the cursor and be able to use the terminal
"nohup" is to run and not die when closing the terminal

Most of the times, only the "&" is fine. Try it like this...

# open the terminal
google-chrome "https://stackoverflow.com" "https://github.com" &
# hit enter to get the prompt back and close the terminal with Ctrl+d
0
On

For first part of question:

nohup google-chrome "https://stackoverflow.com" "https://github.com" &>/dev/null & disown %%  

I can't explain how this works. But it works :-) Found somewhere on the Internet