I’ve got an NSPasteboard:
NSPasteboard *pasteboard;
and get it with:
pasteboard = [[NSPasteboard generalPasteboard] retain];
Now I want to determine of what type the last entry is, like formatted text or image etc. and if text, get the contents of it etc.
How do I find out the type of data hold in the pastboard?
I logged the output from [pasteboard types]:
2011-05-07 20:13:30.491 YourApp[15335:903] Pasteboard changed: (
"public.utf8-plain-text",
NSStringPboardType,
"dyn.ah62d4rv4gu8y63n2nuuhg5pbsm4ca6dbsr4gnkduqf31k3pcr7u1e3basv61a3k",
"NeXT smart paste pasteboard type"
)
but I’m not sure how to check if it’s text or anything else…
This is covered fully in the Pasteboard Programming Guide. The standard way to do this is to make a list of the types you are interested in and then just ask the pasteboard to give you those types. If it has objects of those types, you get them. Otherwise, you get nothing.
You can also make multiple inquiries with different lists of types:
You can also simply ask the pasteboard if it has one of the types you’re interested in, without actually getting the objects. This will give you a simple
YESorNO:Note that pasteboard handling changed in Snow Leopard, so this is, unfortunately, all different in Leopard.