是否可以在主要功能中调用myHandler()
?我的想法是在开始时自动调用处理程序。 THX
的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 :(得分:0)
您不需要将该命令用作处理程序。只需在此行之后插入命令... on applicationWillFinishLaunching_(sender)。所以你的代码在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