Created
June 6, 2019 06:30
-
-
Save justvanrossum/9843bf52d93cbe1c7a3f37420bea8d34 to your computer and use it in GitHub Desktop.
macOS/Python: Get dimension info about active screens
This file contains 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; {rx:.0f}×{ry:.0f} dpi") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output: