tell application "Safari" set myFile to open for access (choose file name) with write permission set windowNumber to 1 repeat the number of windows times set myTabs to every tab of window windowNumber write "----- Window Number " & windowNumber & " ----- " to myFile set tabNumber to 0 repeat with aTab in myTabs set tabTitle to name of aTab & " " write tabTitle to myFile set tabURL to URL of aTab & " " write tabURL to myFile set tabNumber to tabNumber + 1 end repeat write "Window Number: " & windowNumber & " Number of tabs: " & tabNumber & " " to myFile set windowNumber to windowNumber + 1 end repeat close access myFile end tell
The script, safari_tabs.scpt can be run
using the Script Editor application found in
/Applications/Utilities
. Within the Script Editor click
on File then Open and select the script file.
Then click on the the "run the script" icon, which is a rightward pointing arrow head. Or you can run the script from a command line interface, i.e., a Terminal window using
osascript chrome_tabs.scpt
.
$ osascript safari_tabs.scpt $
The above script only works for Safari. For one that works with
the Google Chrome browser, see
Using AppleScript to
record the Chrome browser windows and tabs. Firefox does not have
a tab
item in its "dictionary." Applications have a
"dictionary" that can be consulted to determine what properties can be
queried or altered. If you have the applications installed on an OS X
system, you can see the dictionaries for Chrome, Firefox,
and Safari, by clicking on File then selecting Open Dictionary
in the Script Editor utility. Scroll through the list until you find
the relevant dictionary. The properties for the tab
item in
Safari's dictionary is shown below: