Thursday, February 25, 2021

#1 2021-01-05 02:16:35 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 625

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.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>$archiver</key>
    <string>NSKeyedArchiver</string>
    <key>$objects</key>
    <array>
        <string>$null</string>
        <dict>
            <key>$class</key>
            <dict>
                <key>CF$UID</key>
                <integer>9</integer>
            </dict>
            <key>MUIWebDocumentAttachments</key>
            <dict>
                <key>CF$UID</key>
                <integer>3</integer>
            </dict>
            <key>MUIWebDocumentHTML</key>
            <dict>
                <key>CF$UID</key>
                <integer>2</integer>
            </dict>
            <key>MUIWebDocumentJSDocumentContext</key>
            <dict>
                <key>CF$UID</key>
                <integer>5</integer>
            </dict>
            <key>MUIWebDocumentOriginalEncoding</key>
            <integer>10</integer>
        </dict>
        <string>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN


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 ??

Applescript:

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

Applescript:

set theObject to plist's objectForKey:"$objects"
set theString to (theObject's objectAtIndex:2) as text

Last edited by Fredrik71 (2021-01-05 03:02:26 am)


The purpose to study someone else art is not to add, its to make less more.

Offline

 

#2 2021-01-05 05:48:54 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6565

Re: MUIWebDocumentPasteboardType to extract a string

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2021-01-05 06:09:07 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 625

Re: MUIWebDocumentPasteboardType to extract a string

Thanks Shane... I will look at it

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


The purpose to study someone else art is not to add, its to make less more.

Offline

 

#4 2021-01-05 06:53:49 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6565

Re: MUIWebDocumentPasteboardType to extract a string

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#5 2021-01-05 09:53:59 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 625

Re: MUIWebDocumentPasteboardType to extract a string

You could read more about it here...
https://macosx-dev.omnigroup.narkive.co … erformance


The purpose to study someone else art is not to add, its to make less more.

Offline

 

#6 2021-01-05 11:59:21 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 625

Re: MUIWebDocumentPasteboardType to extract a string

Shane I try this but it return a error...

error "*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (MUIWebDocument) for key (root); the class may be defined in source code or a library that is not linked" number -10000



Do you know what is happening ??

The code I use was:

Applescript:

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


The purpose to study someone else art is not to add, its to make less more.

Offline

 

#7 2021-01-05 05:15:20 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6565

Re: MUIWebDocumentPasteboardType to extract a string

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#8 2021-01-06 02:25:43 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 625

Re: MUIWebDocumentPasteboardType to extract a string

Shane Stanley wrote:

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


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.


The purpose to study someone else art is not to add, its to make less more.

Offline

 

#9 2021-01-06 05:11:34 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6565

Re: MUIWebDocumentPasteboardType to extract a string

Fredrik71 wrote:

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



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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#10 2021-01-06 05:50:43 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 625

Re: MUIWebDocumentPasteboardType to extract a string

Shane Stanley wrote:

...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. smile

Thanks again.


The purpose to study someone else art is not to add, its to make less more.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)