Created
January 14, 2010 00:18
-
-
Save crmne/276724 to your computer and use it in GitHub Desktop.
Opens the source of the current Safari page in TextMate.
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 source of the current Safari page in TextMate. | |
-- | |
-- 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 source of 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