Skip to content

Instantly share code, notes, and snippets.

@cesarandreu
Created October 26, 2017 21:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cesarandreu/8d6ccd70bcac81d1a45941ae996a6e32 to your computer and use it in GitHub Desktop.
Save cesarandreu/8d6ccd70bcac81d1a45941ae996a6e32 to your computer and use it in GitHub Desktop.
Get the list of tabs from the frontmost Safari window

Run with osascript:

$ osascript -l JavaScript GetSafariTabs.js

Get the result in your pasteboard by piping to pbcopy:

$ osascript -l JavaScript GetSafariTabs.js | pbcopy
const safari = Application('Safari')
const tabs = safari.windows[0].tabs
const list = []
for (let i = 0; i < tabs.length; i++) {
const url = tabs[i].url()
if (url) {
list.push(url)
}
}
console.log(list.join('\n'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment