Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
macOS/Python: Get dimension info about active screens
from AppKit import NSScreen, NSDeviceSize, NSDeviceResolution
from Quartz import CGDisplayScreenSize
for i, screen in enumerate(NSScreen.screens(), 1):
description = screen.deviceDescription()
pw, ph = description[NSDeviceSize].sizeValue()
rx, ry = description[NSDeviceResolution].sizeValue()
mmw, mmh = CGDisplayScreenSize(description["NSScreenNumber"])
scaleFactor = screen.backingScaleFactor()
pw *= scaleFactor
ph *= scaleFactor
print(f"display #{i}: {mmw:.1f}×{mmh:.1f} mm; {pw:.0f}×{ph:.0f} pixels; {rx:.0f}×{ry:.0f} dpi")
@justvanrossum

This comment has been minimized.

Copy link
Owner Author

@justvanrossum justvanrossum commented Jun 6, 2019

Example output:

display #1: 609.6×345.1 mm; 3840×2160 pixels; 72×72 dpi
display #2: 286.4×179.0 mm; 3360×2100 pixels; 144×144 dpi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.