Applescript to reload a web page in DevonThink Pro via Harvard's EZ-Proxy
I've started reading RSS feeds of various journals from within DEVONThink so I can pull out articles that relate to on-going work. I wanted to be able to "live" within DT for this purpose and not have to open web pages in Safari or Firefox in order to use Harvard's "ezproxy" service. To use Harvard's EZ-Proxy, you append ".ezp2.harvard.edu" to the end of subscription-only journal URL (just the hostname portion) and then log in. So we'd change http://www.nature.com/x/y/z to http://www.nature.com.ezp2.harvard.edu/x/y/z. The problem is that DT doesn't allow you to edit the URL of a loaded web page.
Applescript to the rescue. Now while viewing a web page with "access denied!" from within DT, I can go to the scripts menu and choose Harvard EZProxy Reload and the page is refreshed with the altered URL.
Here's the code:
tell application id "com.devon-technologies.thinkpro2"
try
if not (exists think window 1) then error "No window is open."
set old_URL to the URL of think window 1
set pat to "'s@(https*://[^/]+)@\\1.ezp2.harvard.edu@'"
set new_URL to ¬
do shell script "echo " & quoted form of old_URL & " t| perl -pe " & patset the URL of think window 1 to new_URL
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
end try
end tellNote that the Error -128 exception is from one of DT's own scripts, so I'm not sure what that error is, precisely.
Also note that the ¬ means "continue on next line." You can just delete it and move the "do shell" line up. This was done entirely to make Posterous happy.
Sorry that like many budding AppleScript authors, I wimped out and used Perl to parse the URL.
Feel free to comment as I'm a novice at AppleScript.