MUIWebDocumentPasteboardType to extract a string

I have done some research on Apple mail and find this:MUIWebDocumentPasteboardType
I have extract it to a file and it looks like this, the pasteboardType is binary plist.

The last line is a string I’m intresting in. (HTML Source) of the email.

So I made this code and it give the string but I wonder if there is a better way, to do this ??

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

set thePath to POSIX path of (choose file)
set theURL to current application's |NSURL|'s fileURLWithPath:thePath
set theData to current application's NSData's dataWithContentsOfURL:theURL

set plist to current application's NSPropertyListSerialization's propertyListWithData:theData options:(current application's NSPropertyListImmutable) format:(missing value) |error|:(missing value)
set theObject to plist's objectForKey:"$objects"
set theString to (theObject's objectAtIndex:2) as text
set theObject to plist's objectForKey:"$objects"
set theString to (theObject's objectAtIndex:2) as text

Rather than NSPropertyListSerialization you should use NSKeyedUnarchiver — the presence of NSKeyedArchiver tells you how it was made. Use +unarchiveObjectWithData: or + unarchiveObjectWithFile:.

Thanks Shane… I will look at it

I read on website that NSPropertyListSerialization is faster and NSKeyedUnarchive
Do you share the same experience/knowledge ?

I’m not sure a speed comparison makes sense — they perform different functions.

You could read more about it here…
https://macosx-dev.omnigroup.narkive.com/dRIfpNPL/nspropertylistserialization-vs-nskeyedarchiver-performance

Shane I try this but it return a error…

Do you know what is happening ??

The code I use was:

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

set thePath to POSIX path of (choose file)
set theURL to current application's |NSURL|'s fileURLWithPath:thePath
set theData to current application's NSData's dataWithContentsOfURL:theURL

set theUnarchiver to current application's NSKeyedUnarchiver's unarchiveObjectWithData:theData

It means that whatever app is putting that on the clipboard has defined a class called MUIWebDocument, of which this represents an instance.

You earlier code should be OK, but I’m generally nervous about relying on a particular order.

So if I understand you correctly, I couldn’t use NSKeyedUnarchiver or would it involve a more
complicated process.

I need to read more about this because my knowledge is very limited, I have never done any
examples with NSKeyedArchive before. The first time I heard about it was when I read on wikipedia
about webarchive.

The approach we choose for the moment maybe are not what we want, but its bold to do something
more complicated because in return we could learn something new from it.

Thanks for your input.

That’s correct. You’d have to do something like create a version of the class yourself, reverse-engineering parts of it from the property list. It may or may not even be possible.

I feel more luck with: If I ever meet Tim Cook in person he will give me the source code of Apple Mail. :slight_smile:

Thanks again.