How to get the desktop resolution in Mac via Python?

前端 未结 4 1431
渐次进展
渐次进展 2021-02-15 13:52

Trying to write a python application that downloads images from an RSS feed, and makes a composite background. How do I get the current desktop resolution on Mac OS X (leopard?)

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-15 14:47

    If you are doing this from a LaunchAgent script, you may need to drop down to CoreGraphics primitives rather than AppKit-level methods. Working on this today, my LaunchAgent-loaded script gets None back from NSScreen.mainScreen(), but works fine if I load it from a terminal in my session.

    from Quartz import CGDisplayBounds
    from Quartz import CGMainDisplayID
    
    def screen_size():
        mainMonitor = CGDisplayBounds(CGMainDisplayID())
        return (mainMonitor.size.width, mainMonitor.size.height) 
    

提交回复
热议问题