Create a gist now

Instantly share code, notes, and snippets.

Cocoa Python code to generate an image file for the current Mac model
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)
cgRef, rect = image.CGImageForProposedRect_context_hints_(NULL, None, None)
imageRep = NSBitmapImageRep.alloc().initWithCGImage_(cgRef)
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