On 29 Nov 2005, at 23:09, Alec B. Beardsley wrote:

Has anyone come up with a way to view the source of the current page from safari in textmate?


I wrote this AppleScript:

try
tell application "Safari"
if not (exists document 1) then
display dialog "You need to open a web location first!" buttons {"OK"} default button 1
return
end if
set mySource to the source of front document as text
if (length of mySource is 0) then
display dialog "You need to open a web location first!" buttons {"OK"} default button 1
return
end if
set myName to name of front document as text
end tell



tell application "TextMate" to activate


set myName to replace_chars(myName, "http://", "")
set myName to replace_chars(myName, "/", ":")


if (myName ends with ".html") or (myName ends with ".htm") then
set myPath to "/tmp/" & myName
else
set myPath to "/tmp/" & myName & ".html"
end if


do shell script "rm -f " & quoted form of myPath
do shell script "echo " & quoted form of mySource & " >> " & quoted form of myPath
do shell script "open -a TextMate " & quoted form of myPath
end try

on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars

Paste it in Script Editor.app and save as script or application.
You can then use LaunchBar, QuickSilver, etc. to launch it...