Skip to content

Instantly share code, notes, and snippets.

@jbranchaud
Created January 10, 2025 17:54
Show Gist options
  • Save jbranchaud/ab69f372bff322ceb72ff49fea527be4 to your computer and use it in GitHub Desktop.
Save jbranchaud/ab69f372bff322ceb72ff49fea527be4 to your computer and use it in GitHub Desktop.
A ScriptKit script to grab URL and title for all Chrome tabs of current window
/** @type {import("@johnlindquist/kit")} */
// Name: Export all Chrome Tabs
// Description: Export all Chrome Tabs to Clipboard
let jxa = await npm("@jxa/run");
let result = await jxa.run(() => {
// This was taking too long for windows with TONS of Chrome tabs. AppleScript
// was timing out.
//
// const extractMetadataForTab = (tab) => {
// const pageData = tab.execute({
// javascript: `(function() {
// return {
// title: document.title,
// description: document.querySelector('meta[name="description"]')?.content,
// keywords: document.querySelector('meta[name="keywords"]')?.content,
// ogImage: document.querySelector('meta[property="og:image"]')?.content
// }
// })()`,
// });
//
// return {
// url: tab.url(),
// ...pageData,
// };
// };
let windows = Application("com.google.Chrome").windows();
let tabs = windows[0].tabs();
return tabs.map((tab) => {
// return extractMetadataForTab(tab);
return {
url: tab.url(),
title: tab.title(),
};
});
});
let prettyJson = JSON.stringify(result, null, 2);
// for debugging...
// await div(
// md(`
// ${prettyJson}
// `)
// );
await copy(prettyJson);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment