是否可以使用可可隐藏一个特定的应用程序?
我知道您可以使用以下代码隐藏所有其他应用程序
[[NSWorkspace sharedWorkspace] performSelectorOnMainThread:@selector(hideOtherApplications) withObject:NULL waitUntilDone:NO];
Run Code Online (Sandbox Code Playgroud)
但是有可能隐藏一个特定的应用程序,例如Safari吗?
如果您的目标是Mac OS 10.6+,则可以使用新NSRunningApplication类:
- (BOOL) hideAppWithBundleID:(NSString *)bundleID
{
NSArray *apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:bundleID];
if ([apps count] == 0)
return NO;
return [(NSRunningApplication *)[apps objectAtIndex:0] hide];
}
Run Code Online (Sandbox Code Playgroud)
你可以用applescript做到这一点:
tell application "System Events" to set visible of process "Safari" to false
Run Code Online (Sandbox Code Playgroud)
或通过调用以下内容从cocoa中调用相同的applescript:
NSString * source = @"tell application \"System Events\" to set visible of process \"Safari\" to false";
NSAppleScript * script = [[NSAppleScript alloc] initWithSource:source];
[script executeAndReturnError:nil];
[script release];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2094 次 |
| 最近记录: |