AppScript issues with Cocoa NSString and AppleScript text types?

910 views Asked by At

In one of my Applications I've added a few new properties to the document class of the Standard AppleScript suite. Some of these properties have the type text, others have the type boolean. I've written a "sdef" file and added if to the resources of my App.

But when I launch the App, there are messages in the Console like this:

.sdef warning for type 'text' attribute 'title' of class 'window' in suite 'Standard Suite': AppleScript name references may not work for this property because its type is not NSString-derived.

And when I actually try to get the value from such a new property with type text from within an AppleScript, it will fail. The correct method within my App is called, and it returns the correct value as NSString, but the AppleScript returns with an error. There's a message in the Console again:

Error while returning the result of a script command: the result object... "the requested NSString value" ...could not be converted to an Apple event descriptor of type 'text'. This instance of the class '__NSCFString' returned nil when sent -objectSpecifier (is it not overridden?) and there is no coercible type declared for the scripting class 'text'.

Which probably means that it was not possible to convert the Cocoa NSString object into an AppleScript text object.

When I try to get the value from one of the new boolean properties, it works just fine.

What exactly do I need to do to convert a NSString object into an AppleScript text object?

1

There are 1 answers

0
markhunte On

I suspect you need to coerce the text parameter into a NSString.

I.e

Set sometextString to current application's NSString's stringwithTring:atext

Use it in your method

And to return it you do.

Return sometextString as text