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?

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?

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.

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.

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

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

https://www.macosxautomation.com/applescript/apps/helpers.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.

Thanks, Shane.

An example is a great way to learn. :slight_smile:

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/10/18/applescript-easter-egg-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!