Created
October 26, 2010 17:11
-
-
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
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
(* | |
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