Export Safari tabs to PDF, URL list, or Markdown links via AppleScript Safari tabs to PDF -- Set the destination folder for PDFs (Desktop) set destinationFolder to (path to desktop folder as string) -- Get all Safari tabs tell application "Safari" activate set allWindows to every window set tabCounter to 0 -- Loop through all windows repeat with aWindow in allWindows set allTabs to every tab of aWindow -- Loop through all tabs in each window repeat with aTab in allTabs set tabCounter to tabCounter + 1 set tabURL to URL of aTab set tabTitle to name of aTab -- Clean the title for use as filename set cleanTitle to my cleanFilename(tabTitle) -- Create unique filename with counter set pdfFileName to (tabCounter as string) & "_" & cleanTitle & ".pdf" set pdfFilePath to POSIX path of (destinationFolder & pdfFileName) -- Switch to the tab tell aWindow to set current tab to aTab delay 0.5 -- Use System Events to handle the save dialog tell application "System Events" tell process "Safari" -- Open Export as PDF dialog click menu item "Export as PDF…" of menu "File" of menu bar 1 delay 1 -- Wait for save dialog to appear repeat until exists sheet 1 of window 1 delay 0.1 end repeat -- Clear existing filename and enter new one set value of text field 1 of sheet 1 of window 1 to pdfFileName delay 0.5 -- Navigate to Desktop using keyboard shortcut keystroke "d" using {command down, shift down} delay 0.5 -- Save the file click button "Save" of sheet 1 of window 1 -- Wait for save to complete repeat while exists sheet 1 of window 1 delay 0.1 end repeat delay 0.5 end tell end tell end repeat end repeat display dialog "Saved " & tabCounter & " tabs as PDFs to Desktop" buttons {"OK"} default button "OK" end tell -- Function to clean filename by removing illegal characters on cleanFilename(originalName) set illegalChars to {":", "/", "\\", "|", "*", "?", "\"", "<", ">", "[", "]", "{", "}"} set cleanName to originalName repeat with illegalChar in illegalChars set AppleScript's text item delimiters to illegalChar set textItems to text items of cleanName set AppleScript's text item delimiters to "_" set cleanName to textItems as string end repeat -- Remove leading/trailing spaces and dots set cleanName to my trimText(cleanName) -- Limit filename length (leaving room for counter and extension) if length of cleanName > 200 then set cleanName to text 1 thru 200 of cleanName end if -- Ensure filename isn't empty if cleanName is "" then set cleanName to "Untitled" return cleanName end cleanFilename -- Helper function to trim text on trimText(someText) set theChars to {" ", ".", tab} repeat while first character of someText is in theChars if length of someText is 1 then return "Untitled" else set someText to text 2 thru -1 of someText end if end repeat repeat while last character of someText is in theChars if length of someText is 1 then return "Untitled" else set someText to text 1 thru -2 of someText end if end repeat return someText end trimText Safari tabs to URL list set urlList to "" tell application "Safari" repeat with w in windows repeat with t in tabs of w set urlList to urlList & (URL of t) & linefeed end repeat end repeat end tell -- Save to Desktop set filePath to (path to desktop as text) & "Safari_URLs.txt" do shell script "echo " & quoted form of urlList & " > " & quoted form of POSIX path of filePath display notification "URLs saved to Desktop" with title "Safari URL Export" Safari tabs to Markdown links set urlList to "# Safari Tabs - " & (current date) & linefeed & linefeed tell application "Safari" repeat with w in windows repeat with t in tabs of w set urlList to urlList & "- [" & (name of t) & "](" & (URL of t) & ")" & linefeed end repeat end repeat end tell -- Save as markdown file set filePath to (path to desktop as text) & "Safari_URLs.md" do shell script "echo " & quoted form of urlList & " > " & quoted form of POSIX path of filePath display notification "Markdown links saved to Desktop" with title "Safari URL Export" ❧ 2025-08-18