我有一个可以通过这个终端命令导入 XML 文件的应用程序:
打开 /path/to/main\ app.app --args myXML.xml
这很好用,没有问题。我已经使用 Applescript 通过 shell 启动了这个命令,它也能正常工作。然而,当尝试使用以下代码使用 Cocoa 的 NSTask Launcher 时:
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/open"];
[task setCurrentDirectoryPath:@"/Applications/MainApp/InstallData/App/"];
[task setArguments:[NSArray arrayWithObjects:[(NSURL *)foundApplicationURL path], @"--args", @"ImportP.xml", nil]];
[task launch];
应用程序将启动到初始屏幕,然后在单击下一步按钮或尝试关闭窗口时崩溃。我尝试过使用 NSAppleScript :
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"tell application \"Terminal\" do script \"open /Applications/MainApp/InstallData/App/Main\\\\ App.app\" end tell"];
NSDictionary *errorInfo;
[script executeAndReturnError:&errorInfo];
这将启动程序,它也会崩溃,我在 Xcode 调试窗口中收到此错误:
12011-01-04 17:41:28.296 LaunchAppFile[4453:a0f]
Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.
Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
LaunchAppFile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
所以通过研究我想出了这个:
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"do shell script \"arch -i386 osascript /Applications/MainApp/InstallData/App/test.scpt\""];
NSDictionary *errorInfo;
[script executeAndReturnError:&errorInfo];
但这会导致与最后一个命令相同的结果。关于导致这次崩溃的任何想法?