Is it possible to open in default browser a URL from command line reusing same tab? I know that I can use open command to open a URL in a default browser like:

$ open http://google.com


But what I would like is to execute a similar or same command to open different URLs one after the other, but reusing the same tab of the browser.

Something similar to the HTML version of what I'm trying to achieve:

&lt;a href="http://google.com" target="my_target_window"&gt;Same tab&lt;/a&gt;
You can do this with some AppleScript. For Google Chrome it looks like:

on run argv
  tell application "Google Chrome"
    set URL of active tab of window 1 to item 1 of argv
    activate
  end tell
end run


You'd save that as a script file (.scpt) on disk and then call it with osascript from the command line. For example, if you saved that as ~/bin/chrome.scpt you'd do:

osascript ~/bin/chrome.scpt https://apple.stackexchange.com/


to open https://apple.stackexchange.com/ in the first Chrome window's currently active tab. If you wanted to make it a little simpler you could prefix the script with #! so it can be executed directly from your shell like so:

#!/usr/bin/env osascript 
on run argv
  tell application "Google Chrome"
    set URL of active tab of window 1 to item 1 of argv
    activate
  end tell
end run


And then save that as ~/bin/chrome and chmod u+x ~/bin/chrome and call it like so:

~/bin/chrome https://apple.stackexchange.com/