#!/usr/bin/env ruby # stolen from https://superuser.com/questions/489207/get-the-currently-open-tabs-in-google-chrome-via-the-command-line window_count = %x(osascript -e 'tell application "Brave Browser" to get number of windows').to_i exit if window_count == 0 tabs = [] 1.upto(window_count).each do |win| tab_count = %x(osascript -e 'tell application \"Brave Browser\" to get number of tabs in window #{win}').to_i next unless tab_count > 0 1.upto(tab_count) do |tab| title,url = %x(osascript -e 'tell application \"Brave Browser\" to get {title,URL} of tab #{tab} of window #{win}').split(/,/).map(&:strip) tabs << [title, url] end end exit unless tabs.size > 0 tabs.uniq.sort.each { |title, url| puts format("* [%s](%s)", title, url) }