Is it possible to use applescripts in a cocoa application? I have a cocoa app and a applescript studio app that I would like to merge together in one app but I do not want to rewrite all the code.
Applescript Studio apps are in fact fullblown Cocoa apps.
So the answer is: YES.
Short answer: it depends.
Unlike PyObjC or RubyCocoa, AppleScriptKit is not a full two-way bridge, so while the AppleScript part can call into ObjC reasonably well (via the ‘call method’ command), the ObjC part can’t call into the AppleScript part. Therefore any ObjC-to-AS communication has to be done via ugly kludges such as hidden buttons which the ObjC code can ‘click’ to notify the AS code that it needs to fetch some data from the ObjC side. Also, all communication is done via Apple events so there’s no sharing of mutable data such as records/NSDictionaries, lists/NSArrays and script objects/application-defined classes and instances, which may or may not be an issue for you.
If you only need minimal integration between the two halves, or the bulk of your code is on one side or the other, or your AS program is largely view/controller (GUI) code while your ObjC program is mostly model (logic) code, then you should be able to cobble something together. Otherwise, it’s probably best to rewrite one of your applications into the same language as the other [1]. Without knowing more about the structures of the source applications and how you want to combine them, it’s not really possible to give a more specific answer. Though to be honest, if you really want to write hybrid code you’re way better using Ruby or Python than AppleScript as RubyCocoa and PyObjC provide far, far better Cocoa/ObjC integration than AppleScript+Studio ever will.
HTH
has
[1] Which most likely means rewriting the Studio application in ObjC. In that case, you may still be able to save any bits of AS code used to communicate with other applications and invoke that via NSAppleScript/OSAKit. Or you could just rewrite those parts as well via, e.g. objc-appscript.