Get Safari Tab Info

This script uses Apple’s UI scripting to obtain the name and URL of each tab in the front window of Safari. I hope Apple adds scripting support for tabs because this is a poor substitute.

OS version:

set targetURLs to {}
tell application "Safari" to activate

tell application "System Events" to tell application process "Safari"
	set tabNames to name of radio buttons of window 1
end tell

tell application "Safari"
	repeat with thisTab in tabNames
		tell application "System Events"
			tell application process "Safari"
				tell radio button named thisTab of window 1 to click
			end tell
		end tell
		copy {aURL:URL of document of window named thisTab, aTab:contents of thisTab} to end of targetURLs
	end repeat
end tell