Is there a way in code to find out if the Dock on a Mac is located on the bottom, left, or right side of the user's monitor?
Asked
Active
Viewed 2,129 times
8
-
1What do you need it for? – Daniel Oct 10 '11 at 18:57
-
I am working on an app that will dock itself to the bottom or the side of the screen, but only if the current Mac dock isn't there already. – Michael Wildermuth Oct 10 '11 at 20:45
3 Answers
8
NSScreen
has visibleFrame
method, wich returns a rect that doesn't include the area currently occupied by the dock and menu bar. You can compare this rect with the full screen rect(- (NSRect) [NSScreen* frame]
) and determine the dock location.

VenoMKO
- 3,294
- 32
- 38
-
Cool that is what I was originally thinking. I was hoping there was some method that I didn't know of that would return it for me. Thanks again. – Michael Wildermuth Oct 10 '11 at 20:52
6
This is probably simpler…
defaults read com.apple.dock "orientation"
bottom
You can also find out.. autohide
(i.e. 1), large size
(i.e. "65.48148") and magnification
(i.e. 1), etc.

Alex Gray
- 16,007
- 9
- 96
- 118
-
How do I call "defaults read com.apple.dock orientation" from a cocoa app? – Michael Wildermuth Feb 28 '12 at 18:50
-
3`NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *dockParameterYouWant = [[defaults persistentDomainForName:@"com.apple.dock"] valueForKey:@"thatParameterYouWant"];` – Alex Gray Feb 28 '12 at 19:59
-
-
Sorry about that, I didn't mean to click it. I'm still using the other answer currently. – Michael Wildermuth Mar 06 '12 at 18:20
-
does this also work for sandboxed apps? Also any idea on how to get the dock's size? Or a notification when the user hovered it (or an icon in it)? – cocoa coder Nov 03 '12 at 14:08
-
i have no idea if you can access defaults in the sandbox... haven't been able to find a definitive answer anywhere. if you do, let me know. – Alex Gray Nov 03 '12 at 15:03
-
Note that when the dock's position hasn't been set yet, there could be no entry for "orientation". So remember to fall back to a default "bottom" value – AlexPera Dec 27 '22 at 08:48
1
private discovered API used by prefs panel
typedef enum {
kCoreDockOrientationTop = 1,
kCoreDockOrientationBottom = 2,
kCoreDockOrientationLeft = 3,
kCoreDockOrientationRight = 4
} CoreDockOrientation;
extern void CoreDockGetOrientationAndPinning(CoreDockOrientation *outOrientation, CoreDockPinning *outPinning);
// If you only want to set one, use 0 for the other.
extern void CoreDockSetOrientationAndPinning(CoreDockOrientation orientation, CoreDockPinning pinning);

diimdeep
- 1,096
- 17
- 27