I need to copy the complete content of general NSPasteboard to a pasteboard with specified name. I tried this code:
- (void)copyFromGeneralPasteboard {
NSMutableArray *archive = [[NSMutableArray alloc] init];
NSArray *typeArray = [[NSPasteboard generalPasteboard] types];
NSPasteboard *myPasteboard = [NSPasteboard pasteboardWithName:@"SpecialPb"];
[myPasteboard declareTypes:typeArray owner:self];
for (NSPasteboardItem *item in [[NSPasteboard generalPasteboard] pasteboardItems])
{
NSPasteboardItem *archivedItem = [[NSPasteboardItem alloc] init];
for (NSString *type in [item types])
{
NSData *data=[[item dataForType:type] mutableCopy];
if (data) {
[archivedItem setData:data forType:type];
}
}
[archive addObject:archivedItem];
}
[[NSPasteboard generalPasteboard] clearContents];
[myPasteboard writeObjects:archive];
[archive removeAllObjects];}
and I am using this code to check.
- (void)SendToGeneralPasteboard {
NSMutableArray *archive = [[NSMutableArray alloc] init];
for (NSPasteboardItem *item in [[NSPasteboard pasteboardWithName:@"SpecialPb"] pasteboardItems])
{
NSPasteboardItem *archivedItem = [[NSPasteboardItem alloc] init];
for (NSString *type in [item types])
{
NSData *data=[[item dataForType:type] mutableCopy];
if (data) {
[archivedItem setData:data forType:type];
}
}
[archive addObject:archivedItem];
}
[[NSPasteboard generalPasteboard] writeObjects:archive];}
So, I performed a test using IWork Pages and it works with text and attributed text. But, when I tried to run with text and image, the program just copy and paste the text. Besides, I tried to run using just image, it woks too. Could you tell me how can I use my code with any type of data? Thanks.