• 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: Shane Stanley <email@hidden>
  • Date: Thu, 12 Nov 2015 09:34:31 +1100

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.
>
> 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"
...

--
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>


_______________________________________________

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


  • Follow-Ups:
    • Re: More AppleScript-ObjC Bridge Weirdness
      • From: Dave <email@hidden>
References: 
 >More AppleScript-ObjC Bridge Weirdness (From: Dave <email@hidden>)

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