Skip to content

Instantly share code, notes, and snippets.

@crmne
Created October 26, 2010 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crmne/647318 to your computer and use it in GitHub Desktop.
Save crmne/647318 to your computer and use it in GitHub Desktop.
Opens the generated source of the current Safari page in TextMate. Javascript trick thanks to @dpkendal http://gist.github.com/646570
(*
Opens the generated source of the current Safari page in TextMate.
To make it a System Service (with keyboard shorcuts!), visit:
http://iflipbits.com/post/880085979/view-source-in-textmate-for-safari
*)
tell application "Safari"
if not (exists front document) then
display alert "An error as occurred" message "You need to open a web site first!" as warning
return
end if
-- get some informations about the page
set theDocument to front document
set theSource to do JavaScript "window.document.documentElement.outerHTML" in theDocument
set theName to name of theDocument as text
set theText to text of theDocument as text
set theTitle to do shell script "basename " & quoted form of theName
end tell
-- if the document is not a web page, get the text
try
get theSource
on error
set theSource to theText
end try
-- write the temp file using a meaningful name
set thePath to "/tmp/" & theTitle & ".html"
set fp to open for access thePath with write permission
write theSource to fp
close access fp
-- open the temp file in TextMate
tell application "TextMate"
activate
open thePath
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment