Skip to content

Instantly share code, notes, and snippets.

@vorg
Last active August 12, 2022 11:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vorg/50000118e7c44e3967648bcf1c21831b to your computer and use it in GitHub Desktop.
Save vorg/50000118e7c44e3967648bcf1c21831b to your computer and use it in GitHub Desktop.
Copy all Safari tabs title and url as markdown
(*Adapted from https://stackoverflow.com/a/39820517*)
set r to "" -- an empty variable for appending a string
tell application "Safari"
repeat with w in windows -- loop for each window, w is a variable which contain the window object
if exists current tab of w then -- is a valid browser window
repeat with t in tabs of w -- loop for each tab of this window, , t is a variable which contain the tab object
-- get the title (name) of this tab and get the url of this tab
tell t to set r to r & "- [ ] [" & name & "](" & URL & ")" & linefeed -- append a line to the variable (r)
(*
'linefeed' mean a line break
'tell t' mean a tab of w (window)
'&' is for concatenate strings, same as the + operator in Swift
*)
end repeat
end if
end repeat
end tell
set the clipboard to r
return r -- return the string (each line contains a title and an URL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment