我刚开始使用Objective-C,我管理得很好。我最后的挑战是制作一个命令行实用程序,我可以在AppleScript中使用它。但是我的代码不起作用,不在终端中,不在AppleScript中。所以我问你,代码和平的错误是什么,应该是非常简单和容易的?设置文件的图标在命令行工具不起作用
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// -imagePath
// -filePath
NSUserDefaults *args = [NSUserDefaults standardUserDefaults];
NSString *soundPath = [args stringForKey:@"imagePath"];
NSString *filePath = [args stringForKey:@"filePath"];
BOOL worked = [[NSWorkspace sharedWorkspace] setIcon:[[NSImage alloc] initWithContentsOfFile:soundPath] forFile:filePath options:0];
NSLog(@"Worked: %i",worked);
[pool release];
return 0;
}
那么,当你运行它会发生什么? (除了泄漏图像,在这种情况下这是无害的,但却是一种不好的习惯)。 – 2010-01-31 00:05:40
顺便说一下,它在我的机器上完美运行。 – Yuji 2010-01-31 03:00:19