Disabling Mission Control, Spaces, Dashboard and any other external process

偶尔善良 提交于 2019-12-12 03:14:48

问题


I was wondering if it was possible to (for a short period of time) disable and re-enable external processes to an application like Mission Control, Spaces, Expose, Dashboard, etc... within an application, while still allowing the user to use my application?

A way of accomplishing this I found was to use NSTask to disable the processes with the corresponding terminal command. For Example:

- (NSString *)runCommandWithBase:(NSString *)base arguments:(NSArray *)arguments {
//Create the task
NSTask *task = [[NSTask alloc] init];

//Setup the task
[task setLaunchPath:base];
[task setArguments:arguments];
[task setStandardInput:[NSPipe pipe]];
[task setStandardOutput:[NSPipe pipe]];

//Set file handle
NSFileHandle *file = [[NSPipe pipe] fileHandleForReading];

//Run the command
[task launch];

//Return
NSData *returnData = [file readDataToEndOfFile];
return [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];}

and:

NSString *exposeEnable = [self runCommandWithBase:@"/usr/bin/defaults" 
                                            arguments:[NSArray arrayWithObjects:@"write", @"com.apple.dock", @"mcx-expose-disabled", @"-boolean", @"NO", nil]];
    NSLog(@"%@", exposeEnable);

NSString *exposeDisable = [self runCommandWithBase:@"/usr/bin/defaults" 
                                             arguments:[NSArray arrayWithObjects:@"write", @"com.apple.dock", @"mcx-expose-disabled", @"-boolean", @"YES", nil]];
    NSLog(@"%@", exposeDisable);

to disable the properties

I tried this and found it to be completely unstable, as mission control (expose) would not always re-enable - even though the file that controls its enabled property says it is enabled (~/Library/Preferences/com.apple.dock.plist; the property of mcx-expose-disabled). Is there another, easier way, or should I modify my application's design so it does not require these things to be shut off? Can I continue using my current method with some modifications to it so it works (like shutting off different properties in defaults)?

Thanks in advance,

Ben


回答1:


Check the "Kiosk Mode Technical Note" documentation and the NSApplicationPresentationDisableProcessSwitching flag.




回答2:


"should I modify my application's design so it does not require these things to be shut off?"

Very probably, the answer to this is yes. If not for technical, then for UX reasons.



来源:https://stackoverflow.com/questions/8941449/disabling-mission-control-spaces-dashboard-and-any-other-external-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!