How to disable Mac screensaver?

I am writing an application using Apple kiosk mode. I would like to turn off the screen saver, but the "ScreenSaverDefaults" class reports that it is only 32-bit. I can only change the assembly to 32-bit, but I would also like to support 64-bit architectures.

Are there any other frameworks that I should use to turn off the screen saver?

+3
source share
3 answers

What I ended up with was reading the preferences file directly com.apple.screensaverand changing the values idleTimeand askForPasswordso that they are zero. Simple CFPreferencesSynchronizeand everything was fine!

+1
source

-, , , , :

NSTask *readTask = [[NSTask alloc] init];
[readTask setLaunchPath:@"/usr/bin/defaults"];

NSArray *arguments = [NSArray arrayWithObjects:@"-currentHost", @"read", @"com.apple.screensaver", @"idleTime", nil];
[readTask setArguments:arguments];

NSPipe *pipe = [NSPipe pipe];
[readTask setStandardOutput:pipe];

NSFileHandle *file = [pipe fileHandleForReading];

[readTask launch];
[readTask release];

NSData *data = [file readDataToEndOfFile];

NSString *originalValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

, idleTime. ! . :

NSTask *writeTask = [[NSTask alloc] init];
[writeTask setLaunchPath:@"/usr/bin/defaults"];

NSArray *arguments = [NSArray arrayWithObjects:@"-currentHost", @"write", @"com.apple.screensaver", @"idleTime", @"0", nil];
[writeTask setArguments:arguments];

[writeTask launch];
[writeTask release];

! . , , originalValue , @"0", :

NSArray *arguments = [NSArray arrayWithObjects:@"-currentHost", @"write", @"com.apple.screensaver", @"idleTime", originalValue, nil]

!

P.S.: , NSTask , . , , , .

+3

, , (, ), , Apple .

Q & A QA1160:

, .

+3
source

Source: https://habr.com/ru/post/1749039/


All Articles