Skip to content

Instantly share code, notes, and snippets.

@armanbilge
Last active December 21, 2015 10:09
Show Gist options
  • Save armanbilge/6290305 to your computer and use it in GitHub Desktop.
Save armanbilge/6290305 to your computer and use it in GitHub Desktop.
Enables easy access to journals and other resources via Harvard's subscription (requires a Harvard ID).
#!/usr/bin/env osascript
-- HUJA: Harvard University Journal Access
set MY_USERNAME to "username"
set MY_PASSWORD to "password"
set PROXY_SERVER to ".ezp-prod1.hul.harvard.edu"
set loginAnyway to false
tell application "Safari" to set origURL to URL of front document as string
if origURL does not contain "harvard" then
tell application "Safari" to set origURL to URL of front document as string
set AppleScript's text item delimiters to "/"
set URLparts to text items of origURL
set item 3 of URLparts to item 3 of URLparts & PROXY_SERVER
set newURL to URLparts as string
tell application "Safari" to set the URL of the front document to newURL
else
set loginAnyway to true
end if
delay 1
tell application "System Events"
tell application process "Safari"
repeat
set loading to (get properties of button 1 of text field 1 of splitter group 1 of group 2 of tool bar 1 of window 1)
if (accessibility description of loading) does not contain "stop" then exit repeat
end repeat
end tell
end tell
tell application "Safari" to set latestURL to URL of front document as string
if latestURL contains "authenticate" or loginAnyway then
tell application "Safari" to activate
tell application "System Events"
keystroke MY_USERNAME
keystroke tab
keystroke MY_PASSWORD
keystroke return
end tell
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment