Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cocoa Python code to generate an image file for the current Mac model
#!/usr/bin/python
from Cocoa import NSImage, NSImageNameComputer, NSSize, NSMakeSize, NSMakeRect, NSBitmapImageRep, NSPNGFileType, NSData
from CoreGraphics import CGImage
from objc import NULL
size = NSMakeSize(512, 512)
image = NSImage.imageNamed_(NSImageNameComputer)
image.setSize_(size)
cgRef, rect = image.CGImageForProposedRect_context_hints_(NULL, None, None)
imageRep = NSBitmapImageRep.alloc().initWithCGImage_(cgRef)
imageRep.setSize_(image.size())
pngData = imageRep.representationUsingType_properties_(NSPNGFileType, None)
pngData.writeToFile_atomically_("computer.png", True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment