Capture all tabs in Safari as URLs to the clipboard

Sometimes you’re doing research and have a pile of tabs (and windows) open and need to get them into a document to share with coworkers… so I went digging and tweaking and found an Applescript that does the job:

tell application “Safari”
set docText to “”
set windowCount to count (every window where visible is true)
repeat with x from 1 to windowCount
set tabCount to number of tabs in window x
repeat with y from 1 to tabCount
set tabName to name of tab y of window x
set tabURL to URL of tab y of window x as string
set docText to docText & tabName & ” – ” & tabURL & linefeed as string
end repeat
set the clipboard to the docText
end repeat
end tell

You can save it as a standalone script and run it from there, or stick into a script item in Automator and run it as a service.. or even call it from the command line as an Osascript.