Created
January 9, 2018 14:37
-
-
Save scriptingosx/ac6bcfe5f88591607db4d299296520ae to your computer and use it in GitHub Desktop.
Cocoa Python code to generate an image file for the current Mac model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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