objective-cnspasteboardiwork

paste of nsmutableattributed string to public pasteboard loses attributes in pages


I am creating a mac standalone service that puts attributed strings on a pasteboard. When the data is accessed by pages, the string loses its attributes. I am using the following code to paste the string, with the NSReturnTypes value set to NSStringPboardType.

    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Yay, I'm a string"];

[str beginEditing];

[str addAttribute:NSUnderlineStyleAttributeName
               value:[NSNumber numberWithInt:NSUnderlineByWord]
               range:NSMakeRange(0,str.length)];

[str endEditing];

[pboard clearContents];
[pboard writeObjects:[NSArray arrayWithObject:str]];

Non iWork applications such as notes and mail can process the attributes just fine but pages insists on dropping them. How can I create pasteboard data that is processable by pages, keynote, and numbers?

UPDATE: Apparantly iWork applies the current style up to the first newline on text that is pasted over already existing text in the document. I am assuming that paragraph styles are behind this, but would appreciate any help here.

UPDATE2: It appears to be a bug in how pages accepts data from the clipboard.


Solution

  • It appears to be a bug in Pages, or intended behavior. https://discussions.apple.com/message/30971829?ac_cid=op123456#30971829