Created
October 20, 2021 17:52
-
-
Save kjaymiller/c57ab9e5b86a66b1e15930d2a977cd79 to your computer and use it in GitHub Desktop.
CleanTabs and Save to GoodLinks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inspiration: https://brettterpstra.com/2020/11/06/dealing-with-leftover-zoom-tabs-in-the-browser/ | |
// This is a javascript for automation app that removes searches and saves all tabs in the most recent window to Goodlinks | |
browser = Application('Safari').windows[0]; | |
baseTabs = browser.tabs().reverse() | |
glinks = Application('Goodlinks') | |
glinks.includeStandardAdditions = true | |
function getActiveTabList () { | |
//gets the latest version of tabs in the most recent active window | |
browser = Application('Safari').windows[0]; | |
baseTabs = browser.tabs().reverse() | |
return baseTabs | |
} | |
function cleanTabs (tabs) { | |
// closes tabs that match the patterns in patternMatchers | |
closeTabs = tabs.filter(tab => patternMatchers(tab.url())) | |
for (tab of closeTabs) { | |
tab.close() | |
} | |
} | |
function patternMatchers(checkedValue) { | |
//given an array of patterns check each tab for the pattern | |
urls = [ | |
/duckduckgo.com/, | |
/google.com/, | |
] | |
return urls.some(url => url.test(checkedValue)) | |
} | |
function saveTabs(tabs, tags="") { | |
// Saves all the open tabs to goodlinks with the provided tags (space-delimited) | |
for (tab of tabs) { | |
url = encodeURIComponent(tab.url()) | |
_tags = encodeURIComponent(tags) | |
glinksURL = `goodlinks://x-callback-url/save?url=${url}&tags=${_tags}&quick=1` | |
glinks.openLocation(glinksURL) | |
} | |
} | |
// Demo | |
// cleanTabList = cleanTabs(getActiveTabList()) | |
// saveTabs(getActiveTabList(), tags="jxa goodlinks") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment