Forked from typemytype/takeScreenshotAndSaveIt.py.py
Last active
June 15, 2017 20:42
-
-
Save mathieureguer/1e9f5956052fe6700d42b43cd88a9617 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 | |
import os.path | |
from mojo.UI import CurrentSpaceCenterWindow | |
# get a path for a png file next to the ufo | |
path_base = os.path.splitext(CurrentFont().path)[0] | |
path = path_base + ".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