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')) |