Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Quit Safari before the program starts
- tell application "Safari"
- close every window
- end tell
- --empty "Downloads" folder
- tell application "System Events"
- delete (every file of folder ("/Users/97pubs/Downloads"))
- end tell
- --opens DINS website
- tell application "Safari"
- make new document with properties {URL:"https://www.notams.faa.gov/dinsQueryWeb/"}
- activate
- ignoring white space
- tell front document to repeat until its text contains "About DINS"
- end repeat
- end ignoring
- log "Finished loading"
- end tell
- delay 2
- --Function to press DoD banner on DINS website
- to clickClassName(theClassName, elementnum)
- tell application "Safari"
- do JavaScript "document.getElementsByClassName('" & theClassName & "')[" & elementnum & "].click();" in document 1
- end tell
- end clickClassName
- clickClassName("ui-state-default", 0)
- delay 2
- --Function to input ICAO abbreviations on the page
- to inputByName(theName, num, theValue)
- tell application "Safari"
- do JavaScript "
- document.getElementsByName('" & theName & "')[" & num & "].value ='" & theValue & "';" in document 1
- end tell
- end inputByName
- inputByName("retrieveLocId", 0, "kmaf")
- delay 2
- --Function to click "View NOTAMs" on page
- to clickName(theName, elementnum)
- tell application "Safari"
- do JavaScript "document.getElementsByName('" & theName & "')[" & elementnum & "].click();" in document 1
- end tell
- end clickName
- --Clicks "View NOTAMs" on page
- clickName("submit", 0)
- --Waits for next window to completely load before continuing
- tell current application
- tell application "Safari"
- tell window 1
- repeat until (exists tab 2)
- delay 1
- end repeat
- ignoring white space
- tell front tab to repeat until its text contains "DINS Disclaimer"
- end repeat
- end ignoring
- end tell
- end tell
- end tell
- delay 1
- --Clicks "Save all NOTAMs" on page
- clickName("button", 1)
- delay 2
- --Waits for download to complete before continuing
- set someFolder to "/Users/path/to/save/location/" -- put your download folder path here
- if not (waitForFilesToCopy into someFolder for (10 * minutes)) then
- display alert "Error with downloads" message "The downloads did not complete in the time allowed."
- if button returned of the result is "Cancel" then error -128
- end if
- to waitForFilesToCopy into theFolder for timeToWait
- (*
- 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
- *)
- set {theFolder, possible, interval} to {theFolder as text, false, 2} -- change the check interval as desired
- tell application "System Events" to set currentSize to size of disk item theFolder -- get initial size
- repeat (timeToWait div interval) times -- check every interval seconds
- delay interval
- tell application "System Events" to set newSize to size of disk item theFolder -- recheck size
- if (newSize is equal to currentSize) then
- if possible then -- no change since last time
- return true -- success
- else -- one more time...
- set possible to true
- end if
- else -- update size & possible switch
- set {currentSize, possible} to {newSize, false}
- end if
- end repeat
- return false -- fail (timeout)
- end waitForFilesToCopy
- --Rename PDF to "5 Local NOTAMs.pdf"
- tell application "System Events" to set name of file "/Users/path/to/save/location/temp.pdf" to "5 Local NOTAMs.pdf"
- --Move NOTAMs to "CrewPapers" folder
- tell application "Finder"
- move POSIX file "/Users/path/to/save/location/5 Local NOTAMs.pdf" to POSIX file "/Users/path/to/new/location" with replacing
- end tell
- --Close Safari and Preview windows
- tell application "Safari"
- close every window
- end tell
- tell application "Preview"
- close every window
- end tell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement