Listing or testing the types on the NSPasteboard generalPasteboard

asobjc
foundation

#1

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');
})();


(Shane Stanley) #2
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

#3

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