Wednesday, March 29, 2017

#1 2016-09-17 03:05:58 pm

StevenH
Member
Registered: 2016-09-17
Posts: 29

Objective c to AppleScript Objective C

Hi all together.

This is my first post.
First I want to share this link, it helped me a lot to understand how to translate objc to ASOC and vice versa.

https://developer.apple.com/library/mac … Guide.html

Unfortunately - I'm struggling und how to translate "super" from objc to ASOC e.g. when writing subclasses.


Any help appreciated

Steven

Offline

 

#2 2016-09-17 03:21:52 pm

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11429
Website

Re: Objective c to AppleScript Objective C

Hi,

welcome to MacScripter.

super is continue


regards

Stefan

Offline

 

#3 2016-09-17 03:34:42 pm

StevenH
Member
Registered: 2016-09-17
Posts: 29

Re: Objective c to AppleScript Objective C

That's it!!!

Thank you

Offline

 

#4 2016-09-17 09:37:16 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 4963

Re: Objective c to AppleScript Objective C

StevenH wrote:

First I want to share this link

Take it with a grain of salt. In particular, the use of property names without parens is generally a bad idea. And the recommended way to refer to Cocoa classes these days is to use the name as an identifier, rather than as a string. The suggestion that you can skip current application's at the top level of a script by using me or my instead is plain bad advice.

(My favorite line from it is: "NSWindow has a bounds property". Really?)

Last edited by Shane Stanley (2016-09-17 10:12:35 pm)


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#5 2016-09-18 03:00:00 am

StevenH
Member
Registered: 2016-09-17
Posts: 29

Re: Objective c to AppleScript Objective C

Take it with a grain of salt. In particular, the use of property names without parens is generally a bad idea. And the recommended way to refer to Cocoa classes these days is to use the name as an identifier, rather than as a string.

Could you explain these 2 lines a little bit more detailed?

Offline

 

#6 2016-09-18 06:26:13 am

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 4963

Re: Objective c to AppleScript Objective C

StevenH wrote:

Could you explain these 2 lines a little bit more detailed?

Sure. For properties, part of the reason is pragmatic: in some cases just using the identifier without parens simply fails. But in other cases there's a subtle difference. Compare these two:

Applescript:

aString's lowercaseString
aString's lowercaseString()

They return the same thing. But whereas the latter calls the value as a method, the former uses key-value coding -- it's like calling valueForKey:"lowercaseString". And when a method is called, the scripting bridge performs appropriate translation of the result according to the method signature, whereas key-value coding always returns an object.

So if you compare, say, |length| and |length|(), the former will return an object -- an NSNumber -- whereas the latter returns an AppleScript integer. Similarly for something like a range -- one will return the range as a record like {location:0, length:1}, whereas the other will return an NSValue.

As long as you understand and are happy to deal with the issue, it's not a problem. But it does often mean another conversion is necessary, and it's easy to forget. And as I said earler, it sometimes just doesn't work, for reasons unknown.

The classes issue is simply that the last advice I've seen from one of the AS team was that the preferred form is current application's NSString, rather than current application's class "NSString". I don't know whether it makes any difference, although I can imagine they are resolved differently. Obviously in properties like the parent property the string method is generally needed.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#7 2016-09-18 07:41:08 am

StevenH
Member
Registered: 2016-09-17
Posts: 29

Re: Objective c to AppleScript Objective C

They return the same thing. But whereas the latter calls the value as a method, the former uses key-value coding -- it's like calling valueForKey:"lowercaseString". And when a method is called, the scripting bridge performs appropriate translation of the result according to the method signature, whereas key-value coding always returns an object

This helps a lot. Great explanation!
Thank you

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.086 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)