Skip to content

Instantly share code, notes, and snippets.

@rsnemmen
Last active April 2, 2022 22:07
Show Gist options
  • Save rsnemmen/6b787b1bcff3798067fc94318d9b09d5 to your computer and use it in GitHub Desktop.
Save rsnemmen/6b787b1bcff3798067fc94318d9b09d5 to your computer and use it in GitHub Desktop.
Apple script to save the URLs of all currently open tabs in Safari to a text file
-- Set up the initial document
set output to ("List of open tabs in Safari" & linefeed as string) & "=======================" & linefeed as string
tell application "Safari"
-- Count the number of Windows
set numWindows to number of windows
repeat with w from 1 to numWindows
--Count the number of Tabs
set numTabs to number of tabs in window w
repeat with t from 1 to numTabs
-- Set the Tab Name and URL values
set tabName to name of tab t of window w
set tabURL to URL of tab t of window w
-- Create the Tab link and write the code
set output to output & tabURL & " " & tabName & linefeed as string
end repeat
end repeat
end tell
-- Write the entire document to TextEdit
tell application "TextEdit"
activate
make new document
set the text of the front document to output
end tell
@rsnemmen
Copy link
Author

rsnemmen commented Apr 2, 2022

As an alternative for saving groups of tabs for future use, I highly recommend the safari add-on Tab Space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment