set file's icon in a command line utility not working

Posted by Ief2 on Stack Overflow See other posts from Stack Overflow or by Ief2
Published on 2010-01-30T21:43:24Z Indexed on 2010/05/20 22:20 UTC
Read the original article Hit count: 204

Filed under:
|
|

I just began to work with Objective-C and I'm managing pretty well. My last challenge was to make a command line utility, which I could than use in AppleScript. But my code does not work, not in the terminal, not in the AppleScript. So I'm asking you, what's the error in this peace of code, that should be very plain and easy?

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;
}

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about objective-c