Skip to content

Instantly share code, notes, and snippets.

@jschoolcraft
Last active April 4, 2022 12:48
Show Gist options
  • Save jschoolcraft/01b46b3231adb3c68b53b4569b4939e0 to your computer and use it in GitHub Desktop.
Save jschoolcraft/01b46b3231adb3c68b53b4569b4939e0 to your computer and use it in GitHub Desktop.
Print a markdown formatted list of tabs from all Brave windows
#!/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) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment