The “cheap” way to copy/paste is to use StandardAdditions “the clipboard”. For simple content, that works, but not for structured things that may include e.g an NSDate. Example:
The actual content I want to copy/paste are table rows, like this:
set myArray to theArrayController’s selectedObjects()
set the clipboard to (myArray as list)
the clipboard as list -->can raise malloc warning
myArray is an array of NSDictionaries.
If one of the dictionary components (i.e the data in one of the cells of the table) is e.g NSDate, then “the clipboard as list” raises the warning “malloc: reference count underflow for 0x2006c79a0, break on auto_refcount_underflow_error to debug.”
One way to get around this is to convert the selected rows to the AppleScript form by Shane’s “fordDeep”, and that works fine for the kind of data I have. But it feels like doing it the Cocoa way would be the proper way, at least in the long term, and especially if I want to support drag&drop.
So I turn to NSPasteboard instead. But it quickly becomes pretty complicated, since when writing to the pasteboard by (“thePasteboard’s writeObjects_(myArray)”) it reports: “Instances of class NSCFDictionary not valid for NSPasteboard -writeObjects:. The class NSCFDictionary does not implement the NSPasteboardWriting protocol.”
So, then I read a lot about NSPasteboardWriting Protocol, and the Pasteboard Programming Guide, NSPasteboardItem, but it all gets a bit convoluted and above my head.
Is there is simple recipe how to copy/paste table rows from/to an array controller?
I’ve searched for and read some posts in this forum about drag&drop with tables, but it has mostly dealt with file urls or similar into a cell, or moving a single row inside a table, not between documents. Drag&drop of rows between documents would be nice of course, and I guess such a solution would more or less automatically support copy/paste of said rows. Has anyone done this?
–harald