These are some awesome, awesome tools!

This is the one I use, but I am going to dig into these others for nuggets:

tell application "Safari" to set s to source of document 1

tell application "BBEdit"
        activate
        make new text window with properties ¬
                {contents:s, source language:"HTML"}
        -- fix the \n that Safari sent over
        replace "\\n" using "\\r" searching in text 1 of text window 1 ¬
                options {search mode:grep, starting at top:true}
        select insertion point before character 1 of text window 1
end tell

On Mar 14, 2010, at 20:10 , Toadling wrote:

> On Mar 14, 2010, at 5:00 PM, Steve Piercy wrote:
> 
>> Is it possible to do this in Safari?
> 
> One of the scripts I use is similar to Charlie's, but here are two more that 
> you might find useful.
> 
> If you don't use Keyboard Maestro, you can put these scripts into Services 
> created with Automator. Mac OS X 10.6 allows you to assign keyboard shortcuts 
> to Services via the System Preferences -> Keyboard -> Keyboard Shortcuts pref 
> pane.
> 
> -Dennis
> 
> -----
> 
> (1) View Source in BBEdit - displays the current Safari page's HTML markup in 
> BBEdit.
> 
> (2) View Source and Header in BBEdit - displays the current Safari page's 
> HTTP header and HTML markup in BBEdit.
> 
> (3) View DOM in BBEdit - displays the current Safari page's DOM in BBEdit 
> (i.e. includes any changes made locally with JavaScript).
> 
> -----
> 
> (1) View Source in BBEdit
> 
> tell application "Safari"
>   try
>      set docTitle to name of current tab of window 1
>   on error
>      set docTitle to URL of document 1
>   end try
>   set docContent to source of document 1
> end tell
> 
> tell application "BBEdit"
>   activate
>   make new text window with properties {contents:docContent, name:docTitle}
>   set source language of front document to "HTML"
>   select insertion point before character 1 of text window 1
> end tell
> 
> -----
> 
> (2) View Source and Header in BBEdit
> 
> tell application "Safari"
> 
>   set docURL to URL of document 1
> 
>   -- Rather than hard-coding the user agent into the script, ask Safari for 
> it so the script should work unmodified on any recent version of Safari.
> 
>   set browserUserAgent to do JavaScript "navigator.userAgent" in document 1
> 
>   try
>      set docTitle to name of current tab of window 1
>   on error
>      set docTitle to docURL
>   end try
> 
> end tell
> 
> try
> 
>   -- Including the user agent is necessary to deal with situations where the 
> document header depends on browser detection. The "-i" option tells curl to 
> include the header.
> 
>   set docContent to do shell script ("curl --user-agent '" & browserUserAgent 
> & "' -i " & docURL)
> 
> on error errMsg
> 
>   tell application "Safari"
>      display dialog errMsg buttons {"OK"} default button 1 with icon 2
>      return
>   end tell
> 
> end try
> 
> tell application "BBEdit"
>   activate
>   make new text window with properties {contents:docContent, name:docTitle}
>   set source language of front document to "HTML"
>   select insertion point before character 1 of text window 1
> end tell
> 
> -----
> 
> (3) View DOM in BBEdit
> 
> global jsCode
> global docContent
> global docTitle
> 
> set jsCode to "document.documentElement.outerHTML"
> 
> tell application "Safari"
>       set docContent to (do JavaScript jsCode in front document)
>       try
>               set docTitle to name of current tab of window 1
>       on error
>               set docTitle to URL of document 1
>       end try
> end tell
> 
> tell application "BBEdit"
>       activate
>       make new text window with properties {contents:docContent, 
> name:docTitle}
>       set source language of front document to "HTML"
>       select insertion point before character 1 of text window 1
> end tell
> 
> -----
> 
> -- 
> You received this message because you are subscribed to the 
> "BBEdit Talk" discussion group on Google Groups.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/bbedit?hl=en
> If you have a feature request or would like to report a problem, 
> please email "[email protected]" rather than posting to the group.

-- 
Lorin Rivers
Mosasaur: Killer Technical Marketing <http://www.mosasaur.com>
<mailto:[email protected]>
512/203.3198 (m)


-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email "[email protected]" rather than posting to the group.

Reply via email to