Skip to content

Instantly share code, notes, and snippets.

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