Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. --Quit Safari before the program starts
  2. tell application "Safari"
  3. close every window
  4. end tell
  5.  
  6. --empty "Downloads" folder
  7. tell application "System Events"
  8. delete (every file of folder ("/Users/97pubs/Downloads"))
  9. end tell
  10.  
  11. --opens DINS website
  12. tell application "Safari"
  13. make new document with properties {URL:"https://www.notams.faa.gov/dinsQueryWeb/"}
  14. activate
  15. ignoring white space
  16. tell front document to repeat until its text contains "About DINS"
  17. end repeat
  18. end ignoring
  19. log "Finished loading"
  20. end tell
  21.  
  22. delay 2
  23.  
  24. --Function to press DoD banner on DINS website
  25. to clickClassName(theClassName, elementnum)
  26. tell application "Safari"
  27. do JavaScript "document.getElementsByClassName('" & theClassName & "')[" & elementnum & "].click();" in document 1
  28. end tell
  29. end clickClassName
  30.  
  31. clickClassName("ui-state-default", 0)
  32.  
  33. delay 2
  34.  
  35. --Function to input ICAO abbreviations on the page
  36. to inputByName(theName, num, theValue)
  37. tell application "Safari"
  38. do JavaScript "
  39. document.getElementsByName('" & theName & "')[" & num & "].value ='" & theValue & "';" in document 1
  40. end tell
  41. end inputByName
  42.  
  43. inputByName("retrieveLocId", 0, "kmaf")
  44.  
  45. delay 2
  46.  
  47. --Function to click "View NOTAMs" on page
  48. to clickName(theName, elementnum)
  49. tell application "Safari"
  50. do JavaScript "document.getElementsByName('" & theName & "')[" & elementnum & "].click();" in document 1
  51. end tell
  52. end clickName
  53.  
  54. --Clicks "View NOTAMs" on page
  55. clickName("submit", 0)
  56.  
  57. --Waits for next window to completely load before continuing
  58. tell current application
  59. tell application "Safari"
  60. tell window 1
  61. repeat until (exists tab 2)
  62. delay 1
  63. end repeat
  64. ignoring white space
  65. tell front tab to repeat until its text contains "DINS Disclaimer"
  66. end repeat
  67. end ignoring
  68. end tell
  69. end tell
  70. end tell
  71.  
  72. delay 1
  73.  
  74. --Clicks "Save all NOTAMs" on page
  75. clickName("button", 1)
  76.  
  77. delay 2
  78.  
  79. --Waits for download to complete before continuing
  80. set someFolder to "/Users/path/to/save/location/" -- put your download folder path here
  81. if not (waitForFilesToCopy into someFolder for (10 * minutes)) then
  82. display alert "Error with downloads" message "The downloads did not complete in the time allowed."
  83. if button returned of the result is "Cancel" then error -128
  84. end if
  85. to waitForFilesToCopy into theFolder for timeToWait
  86. (*
  87. waits up to the timeToWait for files to be copied/downloaded to theFolder the test is based on the size of the folder not changing after several seconds the rough timeToWait may need to be adjusted if copying several files/folders parameters - theFolder [mixed]: the folder to check timeToWait [integer]: a maximum timeout value in seconds returns [boolean]: true if copy/download finished, false if timeout
  88. *)
  89. set {theFolder, possible, interval} to {theFolder as text, false, 2} -- change the check interval as desired
  90. tell application "System Events" to set currentSize to size of disk item theFolder -- get initial size
  91. repeat (timeToWait div interval) times -- check every interval seconds
  92. delay interval
  93. tell application "System Events" to set newSize to size of disk item theFolder -- recheck size
  94. if (newSize is equal to currentSize) then
  95. if possible then -- no change since last time
  96. return true -- success
  97. else -- one more time...
  98. set possible to true
  99. end if
  100. else -- update size & possible switch
  101. set {currentSize, possible} to {newSize, false}
  102. end if
  103. end repeat
  104. return false -- fail (timeout)
  105. end waitForFilesToCopy
  106.  
  107. --Rename PDF to "5 Local NOTAMs.pdf"
  108. tell application "System Events" to set name of file "/Users/path/to/save/location/temp.pdf" to "5 Local NOTAMs.pdf"
  109.  
  110. --Move NOTAMs to "CrewPapers" folder
  111. tell application "Finder"
  112. move POSIX file "/Users/path/to/save/location/5 Local NOTAMs.pdf" to POSIX file "/Users/path/to/new/location" with replacing
  113. end tell
  114.  
  115. --Close Safari and Preview windows
  116. tell application "Safari"
  117. close every window
  118. end tell
  119. tell application "Preview"
  120. close every window
  121. end tell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement