• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Extracting Rich Text via. AppleScript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Extracting Rich Text via. AppleScript


  • Subject: Extracting Rich Text via. AppleScript
  • From: Scott Thompson <email@hidden>
  • Date: Thu, 30 Jun 2005 01:22:23 -0500

My understanding, from reading the documentation and looking at Sketch and TextEdit, is that if your application wants to return styled text that can be manipulated via. the Text Suite, your code should return an NSTextStorage object when asked for the property that contains the styled text.

In response to a request for a property in my application, I return an NSTextStorage:

- (id) title
{
    NSTextStorage *retVal = [[[NSTextStorage alloc] init] autorelease];

    NSLayoutManager *layoutMgr = [[NSLayoutManager alloc] init];
    [retVal addLayoutManager: layoutMgr];
    [layoutMgr release];

NSMutableAttributedString *richText = [[NSMutableAttributedString alloc] initWithString: [self stringValue]];

/* assign attributes to mutable attributed string here */
[retVal replaceCharactersInRange: NSMakeRange(0, [retVal length]) withAttributedString: richText];
[richText release];


    return retVal;
}

The AppleScript debug log tends to suggest that I've built the text storage object properly (or at the very least, the attributed string) but the script to retrieve this parameter still fails:

2005-06-30 01:12:22.219 MM[3895] Command: Intrinsics.get
Direct Parameter: <NSPropertySpecifier: title of subtopics 1 of centralTopic of orderedDocuments 1>
Receivers: <NSPropertySpecifier: title of subtopics 1 of centralTopic of orderedDocuments 1>
Arguments: {}
2005-06-30 01:12:22.244 MM[3895] Property Value: Main T{NSFont = "Helvetica 14.00 pt. P [] (0x0c9e4bc0) fobj=0x10a580a0, spc=3.89"; } opic 1{
NSFont = "Times-Roman 20.00 pt. P [] (0x10a512b0) fobj=0x10a59a10, spc=5.00";
}
2005-06-30 01:12:22.245 MM[3895] Error while returning the result of a script command: the result object...
Main T{NSFont = "Helvetica 14.00 pt. P [] (0x0c9e4bc0) fobj=0x10a580a0, spc=3.89"; }opic 1{
NSFont = "Times-Roman 20.00 pt. P [] (0x10a512b0) fobj=0x10a59a10, spc=5.00";
}
...could not be converted to an Apple event descriptor of type 'rich text'. This instance of the class 'NSConcreteTextStorage' returned nil when sent -objectSpecifier (is it not overridden?) and there is no coercible type declared for the scripting class 'rich text'.
2005-06-30 01:12:22.245 MM[3895] Result: (null)
2005-06-30 01:12:22.245 MM[3895] Error: 8 "NSInternalScriptError"


I don't understand why my object "could not be converted to an Apple Event descriptor of type 'rich text'". The declaration of "rich text" was copied out of the NSTextSuite into my sdef.

So far as I can tell, TextEdit builds it's NSTextStorage object the exact same way, and yet TextEdit seems content to convert the NSTextStorage objects into "utxt" object descriptors.

Can anyone suggest why my code might be failing?

Scott



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: What is creating this Console message in Tiger
  • Next by Date: Re: Thwarting classdump, etc.
  • Previous by thread: Re: Drawers and Interface Builder
  • Next by thread: Sorting an NSArray
  • Index(es):
    • Date
    • Thread