Last active
August 29, 2015 14:01
-
-
Save n8henrie/220306673887daa4aec5 to your computer and use it in GitHub Desktop.
Pulls up the Google Cached version of the current webpage, even if that webpage won't load.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on get_browser() | |
set valid_browsers to {"Safari", "Google Chrome"} | |
tell application "System Events" | |
set front_app to name of first application process whose frontmost is true | |
if valid_browsers contains front_app then | |
return front_app | |
else | |
set running_apps to (name of every process where background only is false) | |
repeat with valid_browser in valid_browsers | |
if running_apps contains valid_browser then | |
return valid_browser as string | |
exit repeat | |
end if | |
end repeat | |
display dialog "Did not find a valid browser in the front application or in the list of running processes. Please test the script with your browser, and include it in the list if it works." | |
end if | |
end tell | |
end get_browser | |
on make_jscript(original_url) | |
set jscript to "javascript:document.location='http://webcache.googleusercontent.com/search?q=cache:'+escape(" & quoted form of original_url & ");" | |
return jscript | |
end make_jscript | |
set my_browser to my get_browser() | |
if my_browser is "Google Chrome" then | |
tell application "Google Chrome" | |
activate | |
tell active tab of front window | |
set original_url to URL | |
set jscript to my make_jscript(original_url) | |
execute javascript jscript | |
end tell | |
end tell | |
else if my_browser is "Safari" then | |
tell application "Safari" | |
activate | |
tell (first tab whose visible is true) of front window | |
set original_url to URL | |
set jscript to my make_jscript(original_url) | |
do JavaScript jscript | |
end tell | |
end tell | |
else if my_browser is "firefox" then | |
display dialog "Sorry, at the time of composing this script, Firefox doesn't currently offer meaningful AppleScript support. It could probable be done with some UI scripting and sending keystrokes, but I don't use Firefox so I'm not going to go down that route right now. --n8henrie 20140728" | |
end if | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment