• 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
Re: More AppleScript-ObjC Bridge Weirdness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More AppleScript-ObjC Bridge Weirdness


  • Subject: Re: More AppleScript-ObjC Bridge Weirdness
  • From: Dave <email@hidden>
  • Date: Thu, 12 Nov 2015 12:29:09 +0000

> On 11 Nov 2015, at 22:34, Shane Stanley <email@hidden> wrote:
>
> On 12 Nov 2015, at 4:29 AM, Dave <email@hidden> wrote:
>>
>> I restarted my Mac and and added as string on the handler definition and  it started working (not sure which of these helped):
>
> The "as string" did it. Passing from Objective-C to AppleScript uses lazy conversion; it doesn't happen unless you ask for it.

Thanks, I’ve added the “as xxxx” to all my parameters which has the added bonus greatly improves the readably when calling from Objective-C.

>>
>> But now I have another problem with types/classes on the:
>>
>> 			set kMessageID of myDictionary to (the id of myMessage as string)
>> 			set kMessageClass of myDictionary to (the class of myMessage as string)
>>
>> When I look at the returned dictionary I see:
>>
>>   kMessageClass = "\U00abclass outm\U00bb";
>>   kMessageID = 540;
>>
>> Which are not of type NSString which is what I expected. However, if I run the script in the Script Editor I get the String Equivalents:
>>
>> kMessageID:"540”,
>> kMessageClass:"outgoing message"
>
> You're expecting roughly the equivalent of an enum being returned as a string rather than an int in Objective-C, or a constant necessarily matching what it represents. Script Editor has the dictionary loaded so it can do the conversion, but a running app doesn't, so it converts the underlying code as best it can.
>
> You need to test the options and build your own string:
>
> if class of myMessage is outgoing message then
> 	set kMessageClass of myDictionary to "outgoing message"
> …

Yes, I came to the same conclusion but did it a slightly different way, if you do this:

set myClass to the class of myMessage as string

This produces a string something like this: "<<class>> outm”

not sure what the <<>> character(s) are? They are not regular greater/less than chars.

Then in Objective-C I setup a Dictionary at App Startup with contains mappings, e.g. “outm" == “outgoingMessage”.

All the Best
Dave


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >More AppleScript-ObjC Bridge Weirdness (From: Dave <email@hidden>)
 >Re: More AppleScript-ObjC Bridge Weirdness (From: Shane Stanley <email@hidden>)

  • Prev by Date: AppleScript-ObjC Bridge - NSDictionary/Record Question
  • Next by Date: Re: Stack View Question
  • Previous by thread: Re: More AppleScript-ObjC Bridge Weirdness
  • Next by thread: Set editable string into NSTextFieldCell
  • Index(es):
    • Date
    • Thread