The StandardAdditions.sdef indicates that particular data types can be retrieved from the clipboard using the key 'as'.
The clipboardInfo() function reveals what these keys are for Applescript, but is less eloquent in case of Yosemite JavaScript. (I haven't tried 10.11)
"text" and "string" seem to work, but none of the permutations which I have tried for public.html public.rtf «class HTML » «class RTF » rtf html
etc. etc.
Has anyone found the keys that work here (assuming the presence of particular content types on the clipboard ?)
(In the meanwhile there are are, of course, some workable ObjC() alternatives for JXA:
ObjC.import('AppKit');
// Types: 'public.rtf', 'public.html' etc
function pboardUnpacked(strType) {
return ObjC.unwrap(
$.NSPasteboard.generalPasteboard.stringForType(
strType
)
)
}
// Types: 'com.apple.webarchive' etc
function pboardPlist(strType) {
return ObjC.deepUnwrap(
$.NSPasteboard.generalPasteboard.propertyListForType(
strType
)
)
}
but it would be good to have the briefer StandardAdditions idiom to hand as well ...
The correct answer, found by mklement0, (see comments at end of question) is that JXA uses Apple's Uniform Type Identifier strings to identify the types of text held in the clipboard.
For example:
(function() {
ObjC.import('AppKit');
return ObjC.deepUnwrap(
$.NSPasteboard.generalPasteboard.pasteboardItems.js[0].types
);
})();
// e.g. -->
["public.rtf", "public.utf8-plain-text",
"public.utf16-external-plain-text", "dyn.ah62d4rv4gk81n65yru",
"com.apple.traditional-mac-plain-text", "dyn.ah62d4rv4gk81g7d3ru"]