Skip to content

Instantly share code, notes, and snippets.

@hafta
Created February 26, 2021 21:29
Show Gist options
  • Save hafta/2b38e7677772ec0fb204aed46027556e to your computer and use it in GitHub Desktop.
Save hafta/2b38e7677772ec0fb204aed46027556e to your computer and use it in GitHub Desktop.
Prints out the origin, dimensions, and scaling factor for each screen, indicating which is the main screen
#!/usr/bin/python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import sys
from AppKit import NSScreen
def print_screen(name, screen):
print("%20s: scale:%.0f at origin (%6d, %6d) with size %5d by %5d" %
(name,
screen.backingScaleFactor(),
screen.frame().origin.x,
screen.frame().origin.y,
screen.frame().size.width,
screen.frame().size.height))
def main():
mainScreen = NSScreen.mainScreen()
i = 0
for screen in NSScreen.screens():
name = "Screen" + str(i)
if screen == mainScreen:
name = "(main) " + name
print_screen(name, screen)
i = i + 1
sys.exit(0)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment