I am puzzled.
After copying a piece of rtf datas I ran this simple script:
clipboard info
log result
get (the clipboard) as «class RTF »-- don't miss the space after RTF
The log history was :
tell application "Script Editor"
clipboard info
--> {{«class RTF », 1207}, {«class utf8», 19}, {«class ut16», 40}, {uniform styles, 624}, {string, 19}, {scrap styles, 82}, {Unicode text, 38}}
end tell
(*«class RTF », 1207, «class utf8», 19, «class ut16», 40, uniform styles, 624, string, 19, scrap styles, 82, Unicode text, 38*)
tell application "Script Editor"
the clipboard
--> "on clipboardAsRtf()"
Résultat :
error "Impossible de convertir \"on clipboardAsRtf()\" en type «class RTF »." number -1700 from "on clipboardAsRtf()" to «class RTF »
So I tried to use :
use AppleScript version "2.3.1"
use scripting additions
use framework "Foundation"
use framework "AppKit"
tell application "Numbers"
tell document 1 to tell sheet 1
set textItem to make text item
set object text of textItem to my clipboardAsRtf()
properties of every iWork item
end tell
end tell
on clipboardAsRtf()
set |⌘| to current application
set theClipboard to |⌘|'s class "NSPasteboard"'s generalPasteboard()
set clipboardContents to (theClipboard's readObjectsForClasses:{|⌘|'s class "NSAttributedString"} options:({}))'s mutableCopy()
set theAttributedString to clipboardContents's firstObject()'s mutableCopy()
tell theClipboard
its clearContents()
its writeObjects:{theAttributedString}
end tell
return the clipboard
end clipboardAsRtf
But the created box contains the datas as Unicode text with no color or font attributes.
How may I force the clipboard to pass only its rtf piece of data ?
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 20 avril 2020 15:53:55