How to open an new Safari window from Terminal in the current Space?
Now when using the open http://example.com
command it opened the URL as last tab on my first Safari window.
I'm looking for a way to open:
- New Safari window (regardless how many I have opened).
- In the current Space
- From Terminal with the provided URL.
It probably will need some osascript
script, but my AppleScript knowledge is nearly zero…
The bonus could be open two URLs, in two tabs, in a new window in the current Space.
Could anyone help?
Best Answer
Here is an AppleScript that should help you. Open AppleScript Editor and save this as a script. I have modified the source that I found here to support taking arguments on the command line.
Use it like this:
osascript new_window.scpt http://www.google.com http://www.stackoverflow.com
Of course, replace the URLs above with your own URLs.
new_window.scpt
You could even create an alias for this in Terminal and be able to use it easier. I would add the following to
~/.bash_profile
:alias newwindow='osascript /path/to/new_window.scpt'
Call
newwindow
whatever you want. Save.bash_profile
and restart Terminal for it to work.In case anyone is looking for a similar solution for Google Chrome, here is a different take on the same idea.
chrome_new_window.scpt