Ok here is part of the code that is causing the error:
char charlieReturn[10000];
char开发者_高级运维lieReturn[10000] = system("osascript /applications/jarvis/scripts/getTextCharlieResponce.scpt");
self.charlieOutput.stringValue = charlieReturn;
The getTextCharlieResponce.scpt returns something like this: "Hi my name is charlie" and maybe sometimes it will be longer than that. The script returns it plain text. I need help FAST!
Thanks in advance! :D
Elijah
Unfortunately there are many problems in your code.
The
C
functionsystem
does not return the standard output of the script aschar*
.Even with a function which returns
char*
, you can't assign it to a array ofchar
as you did:char* str="aeiou"; char foo[100]; foo[100]=str; /* doesn't work */ foo=str; /* doesn't work either */
Cocoa's string class,
NSString*
, is not a C stringchar*
, although you can easily convert between the two:NSString* str=[NSString stringWithUTF8String:"aeiou"];
If you want a string out of a call to an Apple script, you need to do the following:
Prepare an
NSAppleScript
:NSDictionary* errorDict; NSAppleScript* script=[[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:@"path/to/script" ] error:&errorDict];
Execute and get a reply:
NSAppleEventDescriptor* desc=[script executeAndReturnError:&errorDict]; NSString* result=[desc stringValue];
Release the script:
[script release];
Learn C & Objective-C and have fun!
You're trying to assign a character array to what is presumably an NSString. Try this instead:
self.charlieOutput.stringValue = [NSString stringWithUTF8String:charlieReturn];
精彩评论