我已尝试过此代码,但它适用于下载文件夹(示例路径:/Users/%@/Downloads/
),而不适用于应用程序文件夹。所以我想访问Application/iTunes/contents/
,但我无法访问此路径。
我的代码:
- (IBAction)showTrashPressed:(id)sender
{
NSString *trashPath = [NSString stringWithFormat:@"/Users/%@/Applications/",NSUserName()];
////NSLog(@"%@",trashPath);
//[[NSWorkspace sharedWorkspace] selectFile:trashPath inFileViewerRootedAtPath:@"Finder"];
[[NSWorkspace sharedWorkspace]openFile:trashPath withApplication:@"Finder"];
}
答案 0 :(得分:2)
通常iTunes.app
位于本地域的文件夹Applications
而不是用户域。
因此,您可以将路径指定为文字字符串
NSString *iTunesContentsPath = @"/Applications/iTunes.app/Contents";
[[NSWorkspace sharedWorkspace] openFile:iTunesContentsPath withApplication:@"Finder"];
但问NSWorkspace
路径
NSWorkspace *sharedWorkspace = [NSWorkspace sharedWorkspace];
NSString *iTunesPath = [sharedWorkspace fullPathForApplication:@"iTunes"];
[sharedWorkspace openFile:[iTunesPath stringByAppendingPathComponent:@"Contents"] withApplication:@"Finder"];