Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Bulk convert Safari's Web Archives to PDFs' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Bulk convert Safari's Web Archives to PDFs
Authored by: mr. applescript on Jan 04, '10 05:02:23PM
Here's a script that I use as the source for a Run AppleScript action that follows a Get Specified URLs action to print various webpages to PDF in Preview:
on run {input, parameters}
  
  if my GUIScripting_status() is false then error number -128
  
  repeat with i from 1 to the count of input
    set this_URL to (item i of input) as string
    
    tell application "Safari"
      activate
      make new document with properties {URL:this_URL}
      delay 3
    end tell
    tell application "System Events"
      tell process "Safari"
        keystroke "p" using command down
        repeat until (exists sheet 1 of window 1)
          delay 1
        end repeat
        click menu button "PDF" of sheet 1 of window 1
        delay 1
        tell menu 1 of menu button "PDF" of sheet 1 of window 1
          click menu item "Open PDF in Preview"
        end tell
      end tell
    end tell
    delay 2
    tell application "Safari"
      activate
      close document 1 saving no
    end tell
    
  end repeat
  
  return input
end run

on GUIScripting_status()
  -- check to see if assistive devices is enabled
  tell application "System Events"
    set UI_enabled to UI elements enabled
  end tell
  if UI_enabled is false then
    run script "tell application \"System Preferences\"
      activate
      set current pane to pane id \"com.apple.preference.universalaccess\"
      display dialog \"This script utilizes the built-in Graphic User Interface Scripting architecture of Mac OS X which is currently disabled.\" & return & return & \"You can activate GUI Scripting by selecting the checkbox “Enable access for assistive devices” in the Universal Access preference pane.\" with icon 1 buttons {\"Cancel\"} default button 1
    end tell"
    return false
  else
    return true
  end if
end GUIScripting_status
robg adds: Edited for layout to narrow the page display
Edited on Feb 19, '10 10:39:52AM by robg


[ Reply to This | # ]