Created
August 2, 2012 01:36
-
-
Save mbierman/3232318 to your computer and use it in GitHub Desktop.
Preview HTML from TextWrangler in Safari
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
-- Based on Sam Dutton's http://goo.gl/27XlZ script | |
-- which was based on Mike Piontek's script http://goo.gl/SBkkL | |
-- this is Safari specific | |
-- see https://gist.github.com/3232063 for a Chrome Script. | |
tell application "TextWrangler" to set theFile to file of document 1 | |
tell application "TextWrangler" to save document 1 | |
set appleScriptPath to theFile as text | |
set currentURL to POSIX path of appleScriptPath | |
set currentURL1 to POSIX path of appleScriptPath | |
set currentURL to ("file://" & currentURL) | |
-- this script will get the <title> tag from the web page for comparison below. | |
set theTitle to do shell script "grep -i '<title>' " & currentURL1 & "| sed -e 's#<[^>]*>##g' | sed 's/^[ ]*//;s/[ ]*$//'" | |
tell application "Safari" | |
activate | |
-- using the <title> tag above, we compare to the current open tab. If they are equal, replace the contents, otherwise, open a new tab. | |
set currentTab to current tab of front window | |
set currentName to currentTab's name | |
set currentTab to current tab of front window | |
if (exists window 1) and (currentName is theTitle) then | |
set currentURL to currentURL | |
tell application "System Events" | |
tell process "Safari" | |
keystroke "r" using {command down} | |
end tell | |
end tell | |
-- display dialog "currentURL is: " & currentURL & " exists!" | |
else | |
open location currentURL | |
-- display dialog "does not exist!" | |
end if | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment