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