Pass Variable or String from OS X Cocoa App to Applescript

前端 未结 1 472
耶瑟儿~
耶瑟儿~ 2021-01-15 10:03

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

相关标签:
1条回答
  • 2021-01-15 10:21

    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.

    0 讨论(0)
提交回复
热议问题