While researching a particular topic, I often find myself with like thirty Safari tabs open. If I don’t have time to finish what I was working on or need to switch to something else, these open tabs can be really distracting and they consume system resources for no good reason.
I wrote the following script because I wanted to be able to just dump all the tabs in my topmost Safari window into TaskPaper as tasks, so I could close the window, but still keep track of them and find a better time to finish what I was working on. It’s a good way for me to do a literal context switch - save all the working memory to TaskPaper, and move on to the next thread
Thanks to @jessegrosjean and @complexpoint for helping me resolve an issue with this script.
The script will add a list of your open tabs as children of the current item in your TaskPaper doc. Each item has a subnote that contains the URL. An example screenshot is below. It seems to work pretty reliably, but if you run into an issue where no content gets added to your document even though tabs are definitely open, just give the focus to Safari and then try the script again.
Chrome seems to use the exact same interface. Just replace the word “Safari” with “Google Chrome” in the second line (I have not tested this)
Here’s the code:
function extractSafariTabs() {
const safari = Application("Safari");
const window = safari.windows[0];
return window.tabs().map(tab =>
Object({name: tab.name(), url: tab.url()})
);
}
function saveTabs(editor, options) {
'use strict';
const safariTabs = options.tabList;
editor.outline.groupUndoAndChanges(function() {
const current = editor.selection.endItem;
const items = safariTabs.map(tabEntry => {
const entry = editor.outline.createItem(`- ${tabEntry.name}`);
const urlNote = editor.outline.createItem(tabEntry.url);
entry.appendChildren([urlNote]);
return entry;
});
current.appendChildren(items);
editor.setCollapsed(items);
})
return true
}
const docs = Application("TaskPaper").documents;
docs[0].evaluate({
script: saveTabs.toString(),
withOptions: {
tabList: extractSafariTabs(),
}
});