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?)
On your Mac, choose Apple menu > System Settings, then click Displays in the sidebar. (You may need to scroll down.) Click the pop-up menu next to Resolution on the right, choose Scaled, then select one of the options.
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)
I was having a hard time getting any of this to work so I looked around and put something together that seems to work. I am kinda new at coding so please excuse any errors. If you have any thoughts please comment.
results = str(subprocess.Popen(['system_profiler SPDisplaysDataType'],stdout=subprocess.PIPE, shell=True).communicate()[0])
res = re.search('Resolution: \d* x \d*', results).group(0).split(' ')
width, height = res[1], res[3]
return width, height
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With