Skip to content

Instantly share code, notes, and snippets.

@zats
Last active March 28, 2025 13:09
Show Gist options
  • Select an option

  • Save zats/233d63b8e7845f62c7c200a359b3c076 to your computer and use it in GitHub Desktop.

Select an option

Save zats/233d63b8e7845f62c7c200a359b3c076 to your computer and use it in GitHub Desktop.
Detect dock position on the screen for sandboxed macOS apps
enum DockPosition {
case bottom(NSScreen)
case left(NSScreen)
case right(NSScreen)
case hiddenOrUnknown
}
func detectDockPosition() -> DockPosition {
for screen in NSScreen.screens {
let visible = screen.visibleFrame
let full = screen.frame
let deltaLeft = visible.minX - full.minX
let deltaBottom = visible.minY - full.minY
let deltaRight = full.maxX - visible.maxX
// Top delta is menu bar, ignore
if deltaBottom > 0 {
return .bottom(screen)
} else if deltaLeft > 0 {
return .left(screen)
} else if deltaRight > 0 {
return .right(screen)
}
}
return .hiddenOrUnknown
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment