Created
July 15, 2019 09:53
-
-
Save yeahdongcn/21c10ead7284ca59eac45d445d78e34b to your computer and use it in GitHub Desktop.
Check whether dock is visible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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