我无法使用 NSApplescript 转义包含空格的路径:
// mybashscript is in the bundle app (NSlog grant that is ok!)
NSDictionary*errorDict = nil;
NSAppleScript*mycommand;
NSString *mycommand = [mybashscript stringByReplacingOccurrencesOfString:@" " withString:@"\\ "];
// NSString *mycommand = [[mybashscript stringByReplacingOccurrencesOfString:@" " withString:@"\\ "] stringByReplacingOccurrencesOfString:@"/" withString:@":"]; // another test made
mycommand = [[NSAppleScript alloc] initWithSource:[NSString stringWithFormat:@"do shell script \"%@\" with administrator privileges", escapedPath]];
NSAppleEventDescriptor *eventDescriptor = [sudoPandoraMaker executeAndReturnError: &errorDict];
if (([eventDescriptor descriptorType]) && (errorDict==nil)) {
// if error is nil....is ok.. not this case :-(
} else {
NSLog(@"escapedPath è:%@", escapedPath);
// what's was wrong???
}
上面的代码仅在应用程序位于不包含空格的路径中时才能正常工作,但是当将其移动到名称中包含空格的文件夹或硬盘驱动器中时,NSAppleScript 会失败。有什么建议吗?谢谢