How do I know when an attachment attribute is being added to my NSTextView?

I would take a look at the NSTextStorage delegate method -textStorageDidProcessEditing:, which should be called each time a change is made to the underlying text storage. You can then use the -editedRange, -editedMask, and -changeInLength methods to determine what section of the text storage was changed, and look in that range for any attachments that might be of interest to you.


You might want to take a look at two NSTextStorage delegate methods:

- (void)textStorageWillProcessEditing:(NSNotification *)notification;
/* Delegate can change the characters or attributes */

- (void)textStorageDidProcessEditing:(NSNotification *)notification;
/* Delegate can change the attributes */

Inside textStorageWill/DidProcessEditing, you can call -[NSTextStorage editedMask] and -[NSTextStorage editedRange] to find out what changed and then take action accordingly.