0
我無法逃避使用NSApplescript包含空格的路徑:NSApplescript與空間逃逸路徑「做shell腳本。」
// 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將失敗。任何建議?謝謝
感謝您的回覆,但正如您可以看到「事件錯誤處理程序」已設置,所以我已經建立的問題是具有空格的路徑很難解決(使用NSString)。 我解決了它的解決方法:應用程序必須在/應用程序文件夾中... – Mike97