• 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: AppleScriptObjC oddity
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScriptObjC oddity


  • Subject: Re: AppleScriptObjC oddity
  • From: Shane Stanley <email@hidden>
  • Date: Mon, 13 Jul 2015 13:31:28 +1000

On 13 Jul 2015, at 12:48 pm, Chris Page <email@hidden> wrote:

2. "screens" and "frame" are properties, not functions, so you shouldn't use "()" with them.

Really?

Here's Steve's code and how it looks logged in ASObjC Explorer:

0000.001 [4] set ss to current application's NSScreen's screens()
  --> (NSArray) {(NSScreen) <NSScreen: 0x600000865540>, (NSScreen) <NSScreen: 0x60000026e840>}
0000.001 [5] set leftScreenBox to (ss's objectAtIndex:1)'s frame()
  --> {origin:{x:-2560.0, y:0.0}, size:{width:2560.0, height:1440.0}}

The resulting NSRect is bridged to a record, as at least I would expect.

Here's the code without parens:

0000.002 [6] set ss to current application's NSScreen's screens
  --> (NSArray) {(NSScreen) <NSScreen: 0x600000865540>, (NSScreen) <NSScreen: 0x60000026e840>}
0000.002 [7] set leftScreenBox to (ss's objectAtIndex:1)'s frame
  --> (NSConcreteValue) NSRect: {{-2560, 0}, {2560, 1440}}

You end up with an NSValue containing an NSRect, which you then have to unbox. But how do you unbox it? You get the rectValue property of it. But then you run into exactly the same issue:

With parens:

0000.003 [8] set leftScreenBox to leftScreenBox's rectValue()
  --> {origin:{x:-2560.0, y:0.0}, size:{width:2560.0, height:1440.0}}

Without parens:

0000.003 [8] set leftScreenBox to leftScreenBox's rectValue
  --> (NSConcreteValue) NSRect: {{-2560, 0}, {2560, 1440}}

This is going to happen with every method that doesn't return an object.


Although it may currently work, it is superfluous and the exact meaning of using parenthesis after a property name may change in the future. (e.g., it should probably mean instead "get the property, whose value is a function, then call that function", just as it does when sending the message to an AppleScript object that has a property whose value is a handler.)

You're making me feel very, very nervous...

Last time this issue was discussed here, Chris Nebel weighed in, clarifying that leaving off the parens was equivalent to calling [object valueForKey:propertyname]. But there was no mention of its being the preferred way.

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

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: AppleScriptObjC oddity
      • From: Chris Page <email@hidden>
References: 
 >Re: AppleScriptObjC oddity (From: Chris Page <email@hidden>)

  • Prev by Date: Re: AppleScriptObjC oddity
  • Next by Date: Re: AppleScriptObjC oddity
  • Previous by thread: Re: AppleScriptObjC oddity
  • Next by thread: Re: AppleScriptObjC oddity
  • Index(es):
    • Date
    • Thread