Save Chrome Tabs in a Markdown File and Take Notes with Script Kit

John Lindquist
InstructorJohn Lindquist

Share this video with your friends

Send Tweet
Published 2 months ago
Updated 3 weeks ago

We put a lot of work into browsing the internet every day, it would be a pity to lose it all by closing all of our tabs.

Script Kit can collect all of the tabs you currently have open in Chrome using its getTabs method and store them anywhere you want.

This particular script converts the tabs to markdown links and stores them in a text file on your file system, but you could convert and store them using any approach you can think of.

Install save-tabs

// Name: Save Tabs

import "@johnlindquist/kit"

let tabs = await getTabs()

let tabsMd = tabs
  .map(tab => `* [${tab.title || tab.url}](${tab.url})`)
  .join("\n")

let notes = await editor(tabsMd)

let filePath = home("tab-notes.md")
await ensureFile(filePath)
await appendFile(filePath, notes)

edit(filePath)

Instructor: [0:00] Often before closing a whole bunch of tabs, you want to save them because you're doing research. I'll write a script called Save Tabs. Hit Enter. Script Kit has a utility called getTabs which returns an array of tabs that have title and URL on them.

[0:17] Let's take those tabs and map them. We'll grab each tab and map it to a string, which is just a bullet with the markdown URL syntax. This can be the tab title. This can be the tab.URL. Sometimes the title won't exist, so we'll say this might be to tab URL.

[0:35] Then we'll join these back together, just with the new line here, and we'll call these tabs markdown. Our tabs array should be a bulleted list in markdown. To take some notes on that, we'll pass that markdown into our editor. We'll say tabs MD. If I run Save Tabs, you'll see our editor pops open with markdown of all of the tabs that I've opened in Chrome.

[1:02] I could come in and take notes anywhere inside of here. We'll close this. In order to save this, we'll call this Notes. We'll need a file. We'll call this File Path and just create a file in our home directory. We'll call it Tab Notes.MD. First, we'll ensure that the file exists, so file path.

[1:22] Then we'll append the file each time we save, so file path and pass in our notes. Then just to verify that this is working, we'll pass the file path into edit, so it opens in our editor. I'll fire open save tabs. I'll scroll down to the bottom and take some notes.

[1:42] I'll hit Save here with Command S. You'll see that opens in our editor with all of those tabs and links, and my notes are at the bottom. You could put your notes anywhere in here and that would work. Let's do that again. I'll hit Save Tabs and I'll come down here.

[1:58] Let's say, "This is a great site." Scroll to the bottom and say, "This is the bottom." Hit Save again. You'll see there's our notes there. We'll scroll to the bottom and there's the rest of our notes.

Christine Wilks
Christine Wilks
~ a month ago

I don't know what's going wrong but this script doesn't save my notes. It saves all my browser tabs but not the notes that I add. To double check, I copied and pasted the script above.

John Lindquist
John Lindquistinstructor
~ a month ago

Hmm, curious. 🤔

After the line:

let notes = await editor(tabsMd)

// add this
dev(notes)

Do you see your notes appear in the dev tools?

Christine Wilks
Christine Wilks
~ a month ago

I added the line but the notes don't appear in dev tools either.

John Lindquist
John Lindquistinstructor
~ a month ago

Maybe it wasn't clear in the video, but we use cmd+s when "saving" (and cmd+w when closing) from the await editor(). Maybe that's the issue?

Christine Wilks
Christine Wilks
~ a month ago

Thanks. I'm pretty sure I was using cmd+s yesterday. I tried again after shutting down and restarting my computer this morning and it worked fine the first time. But it didn't save the notes on subsequent tries, whether appending or in a fresh doc.