-
-
Save nicksherman/33f400e8577f93ab6ecdecdd4306985a to your computer and use it in GitHub Desktop.
macOS/Python: Get dimension info about active screens
This file contains hidden or 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
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; reported virtual resolution = {rx:.0f} × {ry:.0f} ppi; actual physical pixel density = {pw/mmw*25.4} × {ph/mmh*25.4} ppi") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output: