Doing some test on wbarchive or (bplist)

Doing some test on webarchive format to extract data but also to understand the binary format
of property list. (bplist)

Maybe it could be useful to someone or maybe you like to share your knowledge.

Have not yet figure out how to extract every data from the dictionary.

use framework "Foundation"
use scripting additions

set thePath to POSIX path of (path to desktop) & "apple.webarchive"

(**
* [Type Method]: dataWithContentsOfFile:
*	Creates a data object by reading every byte from the file at a given path.
*)
set theData to current application's NSData's dataWithContentsOfFile:thePath

(**
* [Type Method]: propertyListWithData:options:format:error:
*	Creates and returns a property list from the specified data.
*)
set {theDict, theError} to current application's NSPropertyListSerialization's propertyListWithData:theData options:0 format:(missing value) |error|:(reference)
if theDict = missing value then
	error (theError's localizedDescription() as text)
end if
set theRecord to theDict as record

set theWebMainResource to WebMainResource of theRecord
-- return WebResourceURL of theWebMainResource
-- return WebResourceFrameName of theWebMainResource
-- return WebResourceMIMEType of theWebMainResource
set theSave to POSIX path of (path to desktop) & "apple.html"
set theData to its WebResourceData of theWebMainResource -- __NSCFData
theData's writeToFile:theSave atomically:true
-- return theData's className() as text
-- return WebResourceTextEncodingName of theWebMainResource

Here I get some html code…

set theData to its WebResourceData of theWebMainResource -- __NSCFData
set theString to current application's NSString's alloc()'s initWithData:theData encoding:(current application's NSUTF8StringEncoding)
theString as text

Doing some test on Sal’s code from Late Night Software forum.
To be able to send webarchive to mail. Its not the same as quicklook share to mail.
Not sure, but something is missing.

use framework "Foundation"
use framework "AppKit"
use framework "WebKit"
use scripting additions

set messageSubject to "HOWDY"
set recipientAddresses to {"johnny-appleseed@apple.com"}

set thePath to POSIX path of (path to desktop) & "apple.webarchive"
set theData to current application's NSData's dataWithContentsOfFile:thePath

set anAttributedString to current application's NSAttributedString's alloc()'s initWithHTML:theData documentAttributes:(missing value)

set aSharingService to current application's NSSharingService's sharingServiceNamed:(current application's NSSharingServiceNameComposeEmail)
if aSharingService's canPerformWithItems:{"someone@somewhere.com"} then
	set aSharingService's subject to messageSubject
	set aSharingService's recipients to recipientAddresses
	tell aSharingService to performSelectorOnMainThread:"performWithItems:" withObject:{anAttributedString} waitUntilDone:false
end if