Last active
June 15, 2017 20:41
-
-
Save typemytype/6c4ee724f61e782c127079c95afbdfa2 to your computer and use it in GitHub Desktop.
take screenshot and save it
This file contains 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
import Quartz | |
import AppKit | |
from mojo.UI import CurrentSpaceCenterWindow | |
# a path where to save the screenshot | |
path = u"~/Documents/test.png" | |
# get the space center window | |
sp = CurrentSpaceCenterWindow() | |
# get the cocoa window object | |
w = sp.window().getNSWindow() | |
# get the window number | |
windowNumber = w.windowNumber() | |
# get the screenshot | |
screenshot = Quartz.CGWindowListCreateImage( | |
Quartz.CGRectNull, # use Quartz.CGRectInfinite for a full screenshot | |
Quartz.kCGWindowListOptionIncludingWindow, | |
windowNumber, | |
Quartz.kCGWindowImageShouldBeOpaque) | |
# convert it to a CIIimage | |
result = AppKit.CIImage.imageWithCGImage_(screenshot) | |
# create a represenation | |
rep = AppKit.NSBitmapImageRep.alloc().initWithCIImage_(result) | |
# get the bitmap data | |
PNGData = rep.representationUsingType_properties_(AppKit.NSPNGFileType, None) | |
# save it to disk | |
PNGData.writeToFile_atomically_(path, False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment