← Back to context

Comment by joemi

7 hours ago

> - Dumping all open Safari tabs to an Obsidian doc

I'd love to do this too. Would you mind sharing how you do it? Or is it trivially easy and not worth explaining? (I haven't looked too deeply into HS yet.)

It's not trivial, but roughly: use AppleScript/osascript to get the URLs, but mostly pass them to a ~50 line Bash script which:

  - Brings in the date path components for the dumped-to folder
  - Makes a hash of the URL for an Obsidian doc (each tab gets their own doc)
  - Uses Chrome command line (--headless --disable-gpu --dump-dom) to save a snapshot of the page contents
  - Uses it again with --screenshot to make a thumbnail
  - Create an Obsidian doc from a template
  - If it's a single tab dump, pass -o to the script, which opens it in Obsidian for review

Lastly, I use the relatively-new Bases feature in Obsidian to make a nice "cards" view of the docs with their thumbnails.

I'm hoping to clean it up at some point and maybe release it, but it's one of those classic one-shot systems that just works for me for now.

I have no idea how that person is doing it, but I suspect it could be using osascript. Here's how I do it from my homegrown Go bookmark tool:

  const fetchTabsScript = `
  tell application "Brave Browser"
      set output to ""
      repeat with w in windows
          repeat with t in tabs of w
              set output to output & (URL of t) & "|||" & (title of t) & "\n"
          end repeat
      end repeat
      return output
  end tell
  `  
  
  func GetOpenTabs() ([]Tab, error) {
   cmd := exec.Command("osascript", "-e", fetchTabsScript)
   output, err := cmd.Output()
    // ...
  }