Using AppleScript vs. AppleScriptObjC, or both

So, I’m about one year into using AppleScriptObjC and it’s really great. In fact it is mind blowing!

However, as I use it wherever it’s possible (for me, with my current knowledge) in order to learn about it as fast as I can, I seem to forget how to do even basic stuff in vanilla AppleScript. That’s not a problem per se, but it is definitely a problem when I need to use AppleScript and AppleScriptObjC in one script. It seems I can’t handle those two things together in a good way - always thinking far too long what to use … That also wouldn’t be a problem if I knew both or at least one language very well, but that’s not the case.

So I’m wondering how others make use of AppleScript and AppleScriptObjC. Do you have a strategy when to use what? Do you think about what to use or is it something that simply happens?

It’s something for which you have to develop your own feel. It also depends to a large extent on what you’re most comfortable using.

My own approach is that if a task or part thereof is relatively simple and AppleScript can do it, I use AppleScript, which is likely to be more efficient in such cases. If it’s something which requires, or is more easily or efficiently performed by, system Objective-C methods, then I use ASObjC. The conversion of data between AppleScript and Objective-C classes takes a certain amount of time, so I try not to flip about between data types more often than is necessary.

I’m relatively new to ASObjC but thought I would respond FWIW.

Early on when writing a script, I try to determine whether a particular task should be done with basic AppleScript or ASObjC, and the criteria I employ in making this decision are reliability and speed. Initially I was bothered when using both basic AppleScript and ASObjC in a script, but I’ve now accepted that I should use whichever works best. Just by way of example, I recently revised a script, and I used a list throughout to perform one task and an array throughout to perform a second task. Afterwards, I ran a timing test and the revised script was indeed faster.

The problem with my approach is that it takes time, because I may have to write a code segment twice to see which is faster. Fortunately, my scripts tend to be simple and I have ample time.

As regards forgetting stuff, that happens no matter what I do, and my solution is a well-organized notebook supplemented with Script Debugger clippings.

I started with AppleScript then need more functionality and started to explore AscObjC.

Then needed more interface use and started in with XCode and AppleScript App.

Then started to add Objective-C classes to the project. Which meant to learning more Objective-C.

I pretty much strictly use Objective-C.
With some AppleScripts via Scripting Bridge or ApplescriptObjC bridging.

But basically learning AsObjC helped me
To transition pretty easily into Objective-C.
Really helpful!

I’m writing Cocoa-Scripting books.

Cocoa Scripting Course Volume #1 NSString (721 samples)

Cocoa Scripting Course Volume #2 NSArray (791 samples)

Cocoa Scripting Course Volume #3 NSDictionary (664 samples + 442 Xcode based ASOC )

1 Like

The benefit to be able to code in ASObjC with your AppleScript is many.

  1. You could extend your knowledge in ASObjC by study code from someone else in Swift and ObjC.
  2. You could also use your knowledge in other scripting language like Python.
  3. Your code could be faster.

To convert ObjC to ASObjC is not difficult if you know the Apple’s framework.