Saturday, March 23, 2019

#1 2019-03-02 12:59:53 pm

GG
Member
Registered: 2019-01-14
Posts: 98

Can AppleScript Handlers be written totally in Objective C?

I'm contemplating trying to tweak some of my applescripts that currently use large numbers of objective C routines. I'm familiar with the hybrid AppleScript Objective C programming. However; can AppleScript Handlers be written totally in Objective C? If so; could someone offer a few simple examples, including how the arguments/parameters are transferred?

Offline

 

#2 2019-03-04 06:14:23 pm

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

Re: Can AppleScript Handlers be written totally in Objective C?

I'm trying to make sense of your post, and it has me confused. I suspect it's the terminology you have used. Could you try again?


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

Offline

 

#3 2019-03-05 08:26:02 am

GG
Member
Registered: 2019-01-14
Posts: 98

Re: Can AppleScript Handlers be written totally in Objective C?

Yes, Shane. I can see that one could be confused by it.

There are many handlers written in AppleScript-ObjectiveC. That is, we make calls to specific  methods from AppleScript. But; I was wondering if one could write a handler totally in some variant of C and call it from AppleScript. I suppose that it would likely require defining and instantiating a class, then calling a method from AppleScript. However; I suppose that one could also extend an existing class as well, to get the same effect.

The reason for doing so is that in larger handlers, the back-and-forth between AppleScript and lower-level routines must impose a performance penalty to some degree. When I was defining some of my handlers, I noted that you had suggested using additional method calls, rather than going back into pure AppleScript. This is what got me thinking about this.

Offline

 

#4 2019-03-05 04:47:31 pm

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

Re: Can AppleScript Handlers be written totally in Objective C?

Yes, you can. if it's an Xcode project, you can simply add Objective-C classes. Otherwise you need to put them in an Objective-C framework, and load and use them just the same way as you do with Foundation or AppKit.


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

Offline

 

#5 2019-03-05 11:39:03 pm

technomorph
Member
Registered: 2017-12-14
Posts: 103

Re: Can AppleScript Handlers be written totally in Objective C?

Hey Shane,

How do you "add Obj-C" classes to your AppleScript code?

Do you add it at the top of your Apple Script code?
Or at the top of your "main.h" file?

GG I'm now feeling in the same boat as you.

I'm moving quite a bit into Xcode and feel that things
would be much cleaner (and maybe faster?) if I moved
some things into Obj-C Classes in Xcode.

This may be a great learning lesson,  I don't think it will be too
difficult as since learning how to use Obj-C in Applescript I've
found it not too hard to transition into programming in Xcode with Obj-C.
Still having a bit of trouble wrapping my head around a few things.

Kerry

Offline

 

#6 2019-03-06 01:05:49 am

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

Re: Can AppleScript Handlers be written totally in Objective C?

If you want to see an example of it in an Xcode project, download my Myriad Helpers here:

https://www.macosxautomation.com/apples … lpers.html

The sample app shows how to use it. In this case, most of the Objective-C is in the form of categories, but there's also one standalone class.


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

Offline

 

#7 2019-03-06 03:20:36 pm

GG
Member
Registered: 2019-01-14
Posts: 98

Re: Can AppleScript Handlers be written totally in Objective C?

Thanks, Shane.

An example is a great way to learn. smile

Offline

 

#8 2019-03-06 06:34:12 pm

technomorph
Member
Registered: 2017-12-14
Posts: 103

Re: Can AppleScript Handlers be written totally in Objective C?

Hahaha and then when I just went to recompile my AppleScript I'm using in Xcode I get the error
"Way Too Long Dude"!

I then went and tried deleting a bunch of stuff and it still errored.

then I googled it and it's an Easter Egg:


http://www.automatedworkflows.com/2012/ … long-dude/

Way Too Long Dude

I had left a Quote open or something...  after reviewing where I made the changes
I made it was able to start to compile and point me towards a few more "line ending"
errors that I had made!

haha   well I guess that other code I got rid of I will no recreate in Xcode...
And probably incorporate using a Data Model as well!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)