0

我正在制作一个 osx 应用程序,它有一个按钮,可以将用户的背景设置为他们的屏幕保护程序。这是我的代码:

-(IBAction)startSaver:(id)sender {     

    NSTask *task;     
    task = [[NSTask alloc] init];     
    [task setLaunchPath: @"/usr/bin/open"];          
    NSArray *arguments;     
    arguments = [NSArray arrayWithObjects: @"-a", (@"/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background"), nil];     
    [task setArguments: arguments];          
    [task launch]; 
}         

出于某种原因,我不断收到此错误: FSPathMakeRef(/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background) failed with error -43.

请帮忙!!

4

1 回答 1

0

来自 文件管理器参考

fnfErr -43 文件或目录未找到;不完整的路径名。

/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background路径不存在。

您还可以使用系统命令:

system("/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background");   

使用 NSTask:

NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath: @"/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine"];
NSArray *arguments;
arguments = [NSArray arrayWithObject:@"-background"];
[task setArguments: arguments];
[task launch];
于 2013-10-21T18:30:44.067 回答