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