Hacker News new | ask | show | jobs
by _7jf7 1831 days ago
This works as is but you’ll want to edit the window position numbers (at the bottom).

  function search {
    local query="${@}"

    osascript -l JavaScript -e "
      browser = Application('Google Chrome')

      google_window = browser.Window().make()
      ddg_window = browser.Window().make()

      google_window.activeTab.url = 'https://duckduckgo.com/?q=${query}'
      ddg_window.activeTab.url = 'https://www.google.com/search?q=${query}'

      google_window.bounds = { 'x': 0, 'y': 0, 'width': 600, 'height': 600 }
      ddg_window.bounds = { 'x': 600, 'y': 0, 'width': 600, 'height': 600 }
    "
  }
It could be improved in a few ways, like:

* Not opening the extra window if Chrome isn’t already running.

* URL-encoding your query.

* Auto-detecting the screen bounds (and Dock).

* Auto-detecting the active browser.

But I didn’t want to turn this comment into a full-fledged gist. As is, this works in Chromium-based browsers (replace the name in the `browser = Application('Google Chrome')` line). Adding support for all of them and Safari is simple: https://gist.github.com/vitorgalvao/5392178