Search code examples
applescriptmacos-carbon

Scriptability (AppleScript) in a Mac Carbon application


I am trying to add AppleScripting support to my non-Cocoa based application.

I'm working the low level functions such as AEGetParamDesc, handling the form / want / seld parameters myself.

My vocabulary offers a class, let's call it "Image". It has a property "name".

I've gotten some Applescript code working, such as:

get Images
get name of every Image
get count Images
get every Image
get first Image
get Image 1

So, basically, access to both the objects and its properties works.

However, when I tried these similar access forms, they all fail:

get Images whose name = "foo"

and

repeat with img in Images
end repeat

In the first case, it appears I'll have to handle a test form.

In the second case, the count operator (cnte) does not request the class object directly but instead uses a cobj operator describing an index object.

This all makes me wonder how far this will go. Will I have to implement every possible syntax and operator of Applescript individually in my code? I'd assume that the "whose" operator would simply combine the requests for "every Image" and "name of Image x" the way I can indivually write them in Applescript, instead of using different AppleEvent formulas for each of them.

Same for whose <boolean-test>. Why doesn't AppleScript simply perform the equality test of name = "foo" itself, as it's a text comparison which should not have to involve my application code at all?

Is there something I'm missing? Can I forward these to AE functions I'm not yet aware of or do I have to handle every possible comparison and flow control command myself?


Solution

  • Thomas Tempelmann (of Find Any File fame?), if you really can't rewrite the app in Cocoa, here is an article I wrote many years ago with some detail about coding (in C) for scriptability pre-Cocoa, including handling formWhose, which you asked about above.

    http://www.mactech.com/articles/develop/issue_28/reuter.html

    The article was published by Apple in its Develop magazine, and included source code I wrote for a sample application called "Sketch". This was years before Apple released its own sample project also named "Sketch." I still have the source code if it would help you.

    Good luck!