PDA

View Full Version : how to reference the source for an OmniWeb page via AppleScript


eYeToEyeRob
2006-06-24, 03:25 PM
I am trying to make an AppleScript to open the HTML source for the current browser tab into BBEdit.

Safari has a property named "source" within the class "document", but I cannot find a similar reference within the OmniWeb properties to the "browser" or "tab" classes. (I am reading through the OmniWeb AppleScript dictionary from the Script Editor.)

By using the "source" property for a Safari document, I can get this to work with this reference:

set safariSource to the source of document 1 as string

Does anyone know if the same kind of thing is possible within OmniWeb?

Thanks,

Rob Johnson

Krioni
2006-06-26, 10:53 AM
IBy using the "source" property for a Safari document, I can get this to work with this reference:


Rob, it seems that OmniWeb does not give the source code for a loaded page via AppleScript directly. However, you can access the source yourself in various ways, since OmniWeb gives you the URL.

The simplest way is to get the address and use a "do shell script" command along with the command-line utility "curl" to get the file:

tell application "OmniWeb"
set pageAddress to address of active tab of browser 1
end tell
do shell script "curl " & quoted form of pageAddress


Another way that uses only OmniWeb is the following:

set downloadFilePath to ((path to desktop) as string) & "pagedownload.html"
tell application "OmniWeb"
set pageAddress to address of active tab of browser 1
OpenURL pageAddress to (POSIX path of downloadFilePath)
end tell


Neither way is ideal. OmniWeb should give access to the source as a property of the tab (NOT the browser, please - that's Safari's broken way of doing things - "there are no tabs in AppleScript").

troyb
2006-06-27, 09:20 AM
We have a request for this in our database, thanks!

eYeToEyeRob
2006-06-30, 08:37 PM
set downloadFilePath to ((path to desktop) as string) & "pagedownload.html"
tell application "OmniWeb"
set pageAddress to address of active tab of browser 1
OpenURL pageAddress to (POSIX path of downloadFilePath)
end tell


Thanks, Krioni !

I couldn't get the OpenURL method to work on my system -- this line resulted in what looked to me like a file containing binary contents when opened with BBEdit:

OpenURL pageAddress to (POSIX path of downloadFilePath)

However, your curl tip did just what I wanted. Here's what I ended up with:

tell application "OmniWeb"
set owAddress to the address of the active tab of the browser of the active workspace
set owUrl to the first item of owAddress
set owSource to (do shell script "curl " & quoted form of owUrl)

tell application "BBEdit"
activate

if exists text window 1 then
make new text document at text window 1 with properties {contents:owSource, source language:"HTML"}
else
make new text window with properties {contents:owSource, source language:"HTML"}
end if
select insertion point before character 1 of text window 1

end tell

end tell

Until there's a formal OW reference, this will do fine...

Thanks again,

Rob