Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yeahdongcn/21c10ead7284ca59eac45d445d78e34b to your computer and use it in GitHub Desktop.
Save yeahdongcn/21c10ead7284ca59eac45d445d78e34b to your computer and use it in GitHub Desktop.
Check whether dock is visible
- (BOOL)isDockVisible
{
pid_t pid = 0;
for (NSRunningApplication *runningApp in
[[NSWorkspace sharedWorkspace] runningApplications]) {
if ([[runningApp bundleIdentifier] isEqualToString:@"com.apple.dock"]) {
pid = [runningApp processIdentifier];
break;
}
}
BOOL isVisible = NO;
CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
for (NSDictionary *entry in (__bridge NSArray*)windowList) {
if ( [[entry objectForKey:(id)kCGWindowOwnerPID] intValue] == pid
&& [[entry objectForKey:(id)kCGWindowLayer] intValue] > 0) {
isVisible = YES;
break;
}
}
CFRelease(windowList);
NSLog(@"%d", isVisible);
return isVisible;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment