I would like to pass a variable to applescript. For example, I type some words in textfield of a Cocoa-App (not cocoa-applescript app).Then, it will be a variable in Applesc
String mashing is evil. Just use AppleScriptObjC; there's no magic or complexity to it.
Assuming your application is built using the Cocoa Application template, you will need to 1. include the AppleScriptObjC framework in your project and 2. modify its main.m to match the ASOC template's main.m, which contains two extra lines:
#import <Cocoa/Cocoa.h>
#import <AppleScriptObjC/AppleScriptObjC.h>
int main(int argc, char *argv[])
{
[[NSBundle mainBundle] loadAppleScriptObjectiveCScripts];
return NSApplicationMain(argc, (const char **)argv);
}
Once you've done that, you can add ASOC-style script object files to your project and they'll look just like native classes to the rest of your ObjC program, e.g.:
-- FooTest.applescript
script FOOTest
property parent : class "NSObject"
on doSomething_(sender)
display dialog "Hello World"
end
end script
See this answer for useful links.