2017-08-10 36 views
0

myHandler()を主な機能に呼び出すことはできますか?私の考えは、最初は自動的にハンドラを呼び出すことです。 THXmain関数でハンドラを呼び出すことはできますか?

main.m:

#import <Cocoa/Cocoa.h> 
#import <AppleScriptObjC/AppleScriptObjC.h> 

int main(int argc, const char * argv[]) { 
    [[NSBundle mainBundle] loadAppleScriptObjectiveCScripts]; 
    return NSApplicationMain(argc, argv); 
} 

AppDelegate.applescript:

script AppDelegate 

on myHandler() 
    say "Welcome,sir." 
end myHandler 

on applicationWillFinishLaunching_(sender) 
    -- Insert code here to initialize your application before any files are opened 
end applicationWillFinishLaunching_ 

on applicationShouldTerminate_(sender) 
    -- Insert code here to do any housekeeping before your application quits 
    return current application's NSTerminateNow 
end applicationShouldTerminate_ 

end script 

答えて

0

あなたはハンドラとしてそのコマンドを使用する必要はありません。この行の後に... applicationWillFinishLaunching_(送信者)にコマンドを挿入するだけです。だからあなたのコードは、AppDelegate.applescriptで次のようになります。

script AppDelegate 

on applicationWillFinishLaunching_(sender) 
    say "Welcome,sir." 
end applicationWillFinishLaunching_ 

on applicationShouldTerminate_(sender) 
    -- Insert code here to do any housekeeping before your application quits 
    return current application's NSTerminateNow 
end applicationShouldTerminate_ 

end script 
+0

@Novice私は自分の提案がどのようにうまくいっているか知りたいです。 – wch1zpink

関連する問題