Parsing Textclippings

I wanna find a better way to parse text clippings
Currently my code looks like this :

set getClip to quoted form of POSIX path of (choose file of type "clpt" without invisibles)
set theData to words of (do shell script "cat " & getClip & "/..namedfork/rsrc") # | xattr -rc ."
set myText to ""

repeat with b in theData
	set b to (b as text)
	if b is "utxt" then exit repeat
	set lg to length of b
	if lg > 1 and b is not in myText then set myText to myText & b & " "
end repeat

return myText

I’m not interested to use oxas plugins or xcode shells.

At some stag it looks like Apple has changed how clippings are saved. The resource fork stuff is still there, but the information is also saved in the file itself as a simple NSDictionary.

So…

use framework "Foundation"
use scripting additions

set thePath to POSIX path of "Macintosh HD:Users:shane:Desktop:Test.textClipping"
set theDict to current application's NSDictionary's dictionaryWithContentsOfFile:thePath
set theString to (theDict's valueForKeyPath:"UTI-Data.public.utf8-plain-text") as text

It looks like it’s also available in other forms, like HTML and RTF (if applicable).

Actually, this is probably better:

use framework "Foundation"
use scripting additions

set thePath to POSIX path of "Macintosh HD:Users:shane:Desktop:Test.textClipping"
set theData to current application's NSData's dataWithContentsOfFile:thePath
set theDict to current application's NSPropertyListSerialization's propertyListWithData:theData options:0 format:(missing value) |error|:(missing value)
set theString to (theDict's valueForKeyPath:"UTI-Data.public.utf8-plain-text") as text

Shane,
Your OS must be newer because I cannot adjust your code to make it work on 10.11

This the output from script no. 1

Script no. 2 isn’t able to compile at line:

Exactly at:
format:

Yes, I’m on 10.14. I suspect the change of format was only made in 10.13 or 10.14.