Batch convert Safari webarchive files to PDF #

via Terminal & textutil/cupsfilter

textutil -convert html *.webarchive && for i in *.html ; do cupsfilter "$i" > "$i".pdf ; done

via Automator & Download URLs as PDFs action

via AppleScript & Safari

-- Keep code for Safari separate from the code for System Events.
tell application "Safari"
   activate
   -- Tell Safari, as the known frontmost application, to display the 'choose folder' dialog.
   set SaveFolderPath to POSIX path of (choose folder with prompt "Select Folder to Save PDF Files")
   tell window 1
       set current tab to tab 1
       set ctabs to (count tabs)
   end tell
end tell

repeat with i from 1 to ctabs
   tell application "System Events"
       tell process "Safari"
           click menu item "Show Reader" of menu "View" of menu bar 1
           click menu item "Export as PDF…" of menu "File" of menu bar 1
           repeat until exists sheet 1 of window 1
               delay 1
           end repeat
           -- The sheet opens alread primed with a file name based on the tab name.
           if (i is 1) then
               -- Make sure the file gets saved to the folder chosen above.
               -- This is only necessary first time round the repeat, as the folder becomes the default next time.
               keystroke "g" using {command down, shift down}
               repeat until exists sheet 1 of sheet 1 of window 1
                   delay 1
               end repeat
               log "passed delay"
               tell sheet 1 of sheet 1 of window 1
                   set value of combo box 1 to SaveFolderPath -- NB. the folder path here, not the file name.
                   click button "Go"
                   
               end tell
           end if
           click button "Save" of sheet 1 of window 1
           click menu item "Close tab" of menu "File" of menu bar 1
       end tell
       
       tell application "Safari" to display dialog "Close after 1 second..." giving up after 1
   end tell
end repeat

via Paparazzi!

via EagleFiler & Web archive to PDF script

See also

/mac | Oct 11, 2020


Subscribe or visit the archives.