Created
August 2, 2012 00:57
-
-
Save mbierman/3232063 to your computer and use it in GitHub Desktop.
AppleScript to preview the current file in TextWranger in Chrome.
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 script (http://goo.gl/27XlZ) | |
-- which was based on Mike Piontek's script (http://goo.gl/SBkkL) | |
-- This is Chrome specific. See https://gist.github.com/3232318 for a Safari 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 "Google Chrome" | |
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. | |
if (exists window 1) and (title of active tab of window 1 is theTitle) then | |
tell window 1 to set URL of active tab to currentURL | |
else | |
open location currentURL | |
end if | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment