How to get Position, Width and Height of Mac OS X Dock? Cocoa/Carbon/C++/Qt

This might help in a hack-free solution, NSScreen provides a method (visibleframe) which subtracts the menu and the Dock from the screen size. The frame method contains both.

[NSStatusBar system​Status​Bar].thickness will return the height of the Menu bar.

https://developer.apple.com/reference/appkit/nsscreen/1388369-visibleframe?language=objc


To expand upon MacAndor's answer, you can infer the dock position by comparing the -[NSScreen visibleFrame] (which excludes the space occupied by the dock and the menu bar) with the -[NSScreen frame] which encompasses the entire screen width and height.

The example code below is dependent on the screen the window resides on. This code can be adapted to work with multiple displays by enumerating through all screens instead of using the window's screen.

// Infer the dock position (left, bottom, right)
NSScreen *screen = [self.window screen];    
NSRect visibleFrame = [screen visibleFrame];
NSRect screenFrame = screen.frame;

if (visibleFrame.origin.x > screenFrame.origin.x) {
    NSLog(@"Dock is positioned on the LEFT");
} else if (visibleFrame.origin.y > screenFrame.origin.y) {
    NSLog(@"Dock is positioned on the BOTTOM");
} else if (visibleFrame.size.width < screenFrame.size.width) {
    NSLog(@"Dock is positioned on the RIGHT");
} else {
    NSLog(@"Dock is HIDDEN");
}

Tags:

C++

Macos

Qt

Dock