0

im making an osx application which has a button that sets the user's background as their screensaver. here's my code:

-(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]; 
}         

for some reason i keep getting this error: FSPathMakeRef(/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background) failed with error -43.

please help!!

1 Answers1

0

From File Manager Reference

fnfErr -43 File or directory not found; incomplete pathname.

/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background path doest exist.

you can also use system command:

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

using 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];
Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
  • thanks the system command works! unfortunately when the command is launched my application freezes :( any ideas? – user2904319 Oct 21 '13 at 18:39
  • system is blocking call. – Parag Bafna Oct 21 '13 at 18:39
  • what do you mean system is blocking the call? when i press the button it works in setting my screensaver as my background – user2904319 Oct 21 '13 at 18:59
  • system() function is blocking. use & at the end of command. system("/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background &"); this will fork your command. – Parag Bafna Oct 21 '13 at 19:06