问题
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