Skip to content

Instantly share code, notes, and snippets.

@kosugi
Created July 25, 2013 18:34
Show Gist options
  • Select an option

  • Save kosugi/6082475 to your computer and use it in GitHub Desktop.

Select an option

Save kosugi/6082475 to your computer and use it in GitHub Desktop.
opens a new tab on Google Chrome and renders given HTML via command-line arguments.
on replace {src, tg, rp}
set oldDel to AppleScript's text item delimiters
set AppleScript's text item delimiters to tg
set myList to text items of src
set AppleScript's text item delimiters to rp
set myText to myList as string
set AppleScript's text item delimiters to oldDel
return myText
end replace
on run argv
set content to ""
repeat with arg in argv
set content to content & " " & arg as Unicode text
end repeat
set content to replace {content, "\r", ""}
set content to replace {content, "\n", "\\n"}
set content to replace {content, "'", "\\'"}
tell application "Google Chrome"
tell window 1
set newTab to make new tab with properties {URL:"about:blank"}
delay 0.5
repeat while loading of newTab
delay 0.5
end repeat
end tell
execute front window's active tab javascript "document.documentElement.innerHTML = '" & content & "';"
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment