diff --git a/chrome.js b/chrome.js index 3431054..d4dd3c3 100755 --- a/chrome.js +++ b/chrome.js @@ -1,10 +1,10 @@ #!/usr/bin/env osascript -l JavaScript /** - * A JXA script and an Alfred Workflow for controlling Google Chrome (Javascript for Automation). + * A JXA script and an Alfred Workflow for controlling Google Chrome (Javascript for Automation). * Also see my "How I Navigate Hundreds of Tabs on Chrome with JXA andĀ Alfred" article at [1] * if you're interested in learning how I created the workflow. - * [1] https://medium.com/@bit2pixel/how-i-navigate-hundreds-of-tabs-on-chrome-with-jxa-and-alfred-9bbf971af02b + * [1] https://medium.com/@bit2pixel/how-i-navigate-hundreds-of-tabs-on-chrome-with-jxa-and-alfred-9bbf971af02b */ ObjC.import('stdlib') @@ -48,7 +48,7 @@ function run(argv) { function chromeControl(argv) { if (argv.length < 1) { usage() } - // --ui flag will cause the questions to be asked using a + // --ui flag will cause the questions to be asked using a // Chrome dialog instead of text in command line. let uiFlagIdx = argv.indexOf('--ui') if (uiFlagIdx > -1) { @@ -83,6 +83,10 @@ function chromeControl(argv) { if (argv.length !== 2) { usage() } const arg = argv[1] focus(arg) + } else if (cmd === 'copy') { + if (argv.length !== 2) { usage() } + const arg = argv[1] + copy(arg) } else { usage() } @@ -182,6 +186,22 @@ function focus(arg) { chrome.activate() } +// Copy a specific tab +function copy(arg) { + let { winIdx, tabIdx } = parseWinTabIdx(arg) + let urlToTitle = {} + let selectedTab = tabIdx; + + chrome.windows().forEach((window, winIdx) => { + window.tabs().forEach((tab, tabIdx) => { + if (tabIdx === selectedTab) { + urlToTitle = tab.url(); + } + }) + }) + println(urlToTitle) +} + // Close duplicate tabs function dedup() { let urls = {} @@ -295,4 +315,4 @@ function parseWinTabIdx(arg) { } return { winIdx, tabIdx } -} \ No newline at end of file +} diff --git a/integrations/Alfred/Chrome Control.alfredworkflow b/integrations/Alfred/Chrome Control.alfredworkflow index 5f7f561..312b9c2 100644 Binary files a/integrations/Alfred/Chrome Control.alfredworkflow and b/integrations/Alfred/Chrome Control.alfredworkflow differ