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.

Revisions

  1. Jeff Schoolcraft revised this gist Apr 4, 2022. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions tabs.rb
    Original file line number Diff line number Diff line change
    @@ -17,6 +17,5 @@
    end

    exit unless tabs.size > 0
    tabs.uniq!.sort!

    tabs.each { |title, url| puts format("* [%s](%s)", title, url) }
    tabs.uniq.sort.each { |title, url| puts format("* [%s](%s)", title, url) }
  2. Jeff Schoolcraft created this gist Apr 2, 2022.
    22 changes: 22 additions & 0 deletions tabs.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #!/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!

    tabs.each { |title, url| puts format("* [%s](%s)", title, url) }