Listing or testing the types on the NSPasteboard generalPasteboard

Can we convert the types of the pasteboardItems to an AppleScript list of strings ?

i.e. the kind of thing that in JavaScript for Automation we might write as:

(() => {

    ObjC.import('AppKit');

    // LISTING

    // pBoardTypes :: Clipboard () -> [String]
    const pBoardTypes = () =>
        ObjC.deepUnwrap(
            $.NSPasteboard.generalPasteboard
            .pasteboardItems.js[0].types
        );

    // OR TESTING

    // pBoardContainsRTF :: Clipboard () -> Bool
    const pBoardContainsRTF = () =>
        ObjC.deepUnwrap(
            $.NSPasteboard.generalPasteboard
            .pasteboardItems.js[0].types
        )
        .includes('public.rtf');

    return pBoardTypes()
        .join('\n');
})();

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

current application's NSPasteboard's generalPasteboard()'s pasteboardItems()'s firstObject()'s |types|() as list
2 Likes

Perfect. firstObject() is exactly what I needed. Thank you.