Guest User

Untitled

a guest
Dec 2nd, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --PREREQUISITE: "downloadLocation" must be a favorite (drag and drop to sidebar in finder)
  2. set downloadLocation to "bevyPDF"
  3. set clickScript to "document.getElementById('book-pager-bar-next').click()"
  4.  
  5. --https://stackoverflow.com/questions/6941630/script-safari-5-1-to-open-a-tab
  6. tell first window of application "Safari"
  7.     activate
  8.     set newTab to make new tab
  9.     set the URL of newTab to "https://bevyengine.org/learn/book/introduction/"
  10.     set the current tab to newTab
  11.     delay 1
  12. end tell
  13.  
  14. set prevURL to "tmp1"
  15. set currURL to "tmp2"
  16. set currPage to 1
  17. repeat until (prevURL = currURL)
  18.     --Slightly modified version of https://apple.stackexchange.com/questions/224392/applescript-save-as-dialog-in-safari-reader-save-as-pdf
  19.     tell application "System Events"
  20.         tell application process "Safari"
  21.             set frontmost to true
  22.             tell menu bar 1
  23.                 click menu item "Show Reader" of menu "View" of menu bar item "View"
  24.                 repeat until menu item "Hide Reader" of menu "View" of menu bar item "View" exists
  25.                 end repeat
  26.                 delay 1
  27.                 click menu item "Export as PDF…" of menu "File" of menu bar item "File"
  28.             end tell
  29.             tell window 1
  30.                 repeat until sheet 1 exists
  31.                 end repeat
  32.                 tell sheet 1
  33.                     keystroke currPage
  34.                     set currPage to currPage + 1
  35.                     click pop up button "Where:"
  36.                     repeat until menu 1 of pop up button "Where:" exists
  37.                     end repeat
  38.                     click menu item downloadLocation of menu 1 of pop up button "Where:"
  39.                     click button "Save"
  40.                 end tell
  41.             end tell
  42.         end tell
  43.     end tell
  44.     tell first window of application "Safari"
  45.         set prevURL to URL of current tab
  46.         do JavaScript clickScript in current tab
  47.         delay 1
  48.         set currURL to URL of current tab
  49.     end tell
  50. end repeat
Advertisement
Add Comment
Please, Sign In to add comment