Pattern/template to create and load a category in a normal script app?

Hi there,

I am new to this forum, but not to Applescript. I’ve used it right from its start with practically every app I know and every stupid workaround I could come up with to do so. Unfortunately I wasn’t able to follow the development of the last few years that closely and had “post-process” all that ASOC stuff now over the last few days.

For me the essence (besides the uncertain future of AS in general) of what I read would be that I can finally do really rich and nice things with that script editor window and a web browser for documentation.

The only thing keeping me from being happy is the lack of support for blocks, which unfortunately are a big thing in Cocoa now.

I saw that one could work around this by writing categories on Cocoa classes which would “simply” remap the needed processing to a handler (delegate pattern or via using a selector). I saw that in the Myriad Helpers source code for sheets and I would like to employ that as a general pattern. Please correct me, if that’s not possible.

I always found it too complicated to write a complete AS extension just for a few calls I need, but writing a category for those few occasions seems exactly the right amount of work I would be willing to invest to be able to use everthing from a scripting window, even if it comes with all the ObjC extras, which, however, seems easier to handle on the ObjC side than on the AS side.

Now, that (much) said, I am still not sure about a good pattern to integrate this into my daily workflow. So I am looking for a good pattern to load and activate the categories so that they would be useable in a script app. I saw the inheritance approach and the load library command approach, but I am not sure (or safe) on how to implement this in the most minimalistic way (say for one ore two classes of an Apple framework). So a standard example template would be helpful.

Also, I wonder if there’s a possible standard pattern (e.g. the mentioned selector mapping), or set thereof, to convert a given block-based method into a selector based approach, so that we could just create a AS compatibility layer via batch processing a framework’s include files.

If that’s not possible in a general approach, I wonder if there are certain patterns for block use identifiable that then could be implemented (and collected here). Either as partially general patterns or for certain frameworks/class sets.

Sorry, if any of that was already posted and I oversaw it.

Ok, lots of text for a first post. But I wanted to add thanks to Shane and others who seemingly keep this all running and from whom I read so many great posts over the last few days.


The easiest was to implement your own categories is to put them in a framework. If they’re just for your own use, you can just put the framework in ~/Library/Frameworks and load it via use statements when needed, otherwise wrapping it in a script library is probably easier. But you can also save code bundles and use ASObjC code to load them. Whatever you do, you need to use method names that aren’t likely to clash, preferably with some kind of prefix.

For blocks, there’s no simple answer. The first thing to look for is ways to avoid them if possible. In some cases you can use repeat loops with a small delay where you can check on a property that indicates completion. Otherwise it’s just a matter of being inventive.