def addImageFile(self, path): photodir = ApplicationData.get('photos') path = os.path.normpath(path) if os.path.dirname(path) != photodir: # scale and copy the image to our photo dir try: image = NSImage.alloc().initWithContentsOfFile_(path) except: NSRunAlertPanel(NSLocalizedString("Camera Capture Error", "Window title"), NSLocalizedString("%s is not a valid image" % path, "Alert panel label"), NSLocalizedString("OK", "Button title"), None, None) return size = image.size() if size.width > 128 or size.height > 128: image.setScalesWhenResized_(True) image.setSize_(NSMakeSize(128, 128 * size.height/size.width)) finalpath = photodir+"/"+os.path.basename(path) prefix, ext = os.path.splitext(finalpath) i= 0 while os.path.exists(finalpath): finalpath = prefix+str(i)+ext image.TIFFRepresentation().writeToFile_atomically_(finalpath, False) self.refreshLibrary()
def addImageFile(self, path): path = os.path.normpath(path) if os.path.dirname(path) != self.storage_folder: # scale and copy the image to our photo dir try: image = NSImage.alloc().initWithContentsOfFile_(path) except: NSRunAlertPanel( NSLocalizedString("Camera Capture Error", "Window title"), NSLocalizedString("%s is not a valid image", "Label") % path, NSLocalizedString("OK", "Button title"), None, None) return size = image.size() if size.width > 128 or size.height > 128: image.setScalesWhenResized_(True) image.setSize_(NSMakeSize(128, 128 * size.height / size.width)) finalpath = self.storage_folder + "/" + os.path.basename(path) prefix, ext = os.path.splitext(finalpath) i = 0 while os.path.exists(finalpath): finalpath = prefix + str(i) + ext image.TIFFRepresentation().writeToFile_atomically_( finalpath, False) self.refreshLibrary()
def cropAndAddImage(self, path): try: image = NSImage.alloc().initWithContentsOfFile_(path) except: NSRunAlertPanel(NSLocalizedString("Camera Capture Error", "Window title"), NSLocalizedString("%s is not a valid image" % path, "Alert panel label"), NSLocalizedString("OK", "Button title"), None, None) return rect = NSZeroRect.copy() rect.size = image.size() curSize = self.cropWindow.frame().size if rect.size.width > curSize.width or rect.size.height > curSize.height: self.cropWindowImage.setFrame_(rect) self.cropOriginalImage = image.copy() self.cropWindowImage.setImage_(image) if NSApp.runModalForWindow_(self.cropWindow) == NSOKButton: path = ApplicationData.get('photos') dt = datetime.datetime.now().strftime("%Y%m%d%H%M%S") image = self.cropWindowImage.getCropped() path = path+"/photo%s.tiff"%dt image.TIFFRepresentation().writeToFile_atomically_(path, False) self.cropWindow.orderOut_(None) self.refreshLibrary() else: self.cropWindow.orderOut_(None)
def cropAndAddImage(self, path): try: image = NSImage.alloc().initWithContentsOfFile_(path) except: NSRunAlertPanel(NSLocalizedString("Camera Capture Error", "Window title"), NSLocalizedString("%s is not a valid image", "Label") % path, NSLocalizedString("OK", "Button title"), None, None) return rect = NSZeroRect.copy() rect.size = image.size() curSize = self.cropWindow.frame().size if rect.size.width > curSize.width or rect.size.height > curSize.height: self.cropWindowImage.setFrame_(rect) self.cropOriginalImage = image.copy() self.cropWindowImage.setImage_(image) if NSApp.runModalForWindow_(self.cropWindow) == NSOKButton: dt = datetime.datetime.now().strftime("%Y%m%d%H%M%S") image = self.cropWindowImage.getCropped() tiff_data = image.TIFFRepresentation() #path = self.storage_folder + "/photo%s.tiff" % dt #tiff_data.writeToFile_atomically_(path, False) path = self.storage_folder + "/photo%s.png" % dt bitmap_data = NSBitmapImageRep.alloc().initWithData_(tiff_data) png_data = bitmap_data.representationUsingType_properties_(NSPNGFileType, None) data = png_data.bytes().tobytes() with open(path, 'w') as f: f.write(data) self.cropWindow.orderOut_(None) self.refreshLibrary() else: self.cropWindow.orderOut_(None)
def awakeFromNib(self): smileys = SmileyManager().get_smiley_list() menu = self.smileyButton.menu() while menu.numberOfItems() > 0: menu.removeItemAtIndex_(0) bigText = NSAttributedString.alloc().initWithString_attributes_( " ", NSDictionary.dictionaryWithObject_forKey_( NSFont.systemFontOfSize_(16), NSFontAttributeName)) for text, file in smileys: image = NSImage.alloc().initWithContentsOfFile_(file) if not image: print("cant load %s" % file) continue image.setScalesWhenResized_(True) image.setSize_(NSMakeSize(16, 16)) atext = bigText.mutableCopy() atext.appendAttributedString_( NSAttributedString.alloc().initWithString_(text)) item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( text, "insertSmiley:", "") menu.addItem_(item) item.setTarget_(self) item.setAttributedTitle_(atext) item.setRepresentedObject_( NSAttributedString.alloc().initWithString_(text)) item.setImage_(image)
def cropAndAddImage(self, path): try: image = NSImage.alloc().initWithContentsOfFile_(path) except: NSRunAlertPanel( NSLocalizedString("Camera Capture Error", "Window title"), NSLocalizedString("%s is not a valid image", "Label") % path, NSLocalizedString("OK", "Button title"), None, None) return rect = NSZeroRect.copy() rect.size = image.size() curSize = self.cropWindow.frame().size if rect.size.width > curSize.width or rect.size.height > curSize.height: self.cropWindowImage.setFrame_(rect) self.cropOriginalImage = image.copy() self.cropWindowImage.setImage_(image) if NSApp.runModalForWindow_(self.cropWindow) == NSOKButton: dt = datetime.datetime.now().strftime("%Y%m%d%H%M%S") image = self.cropWindowImage.getCropped() path = self.storage_folder + "/photo%s.png" % dt jpg_data = NSBitmapImageRep.alloc().initWithData_( image. TIFFRepresentation()).representationUsingType_properties_( NSJPEGFileType, {NSImageCompressionFactor: 0.9}) data = jpg_data.bytes().tobytes() with open(path, 'wb') as f: f.write(data) self.cropWindow.orderOut_(None) self.refreshLibrary() else: self.cropWindow.orderOut_(None)
def dragImage(self): if self.cachedDragImage: return self.cachedDragImage self.lockFocus() rep = NSBitmapImageRep.alloc().initWithFocusedViewRect_(self.bounds()) self.unlockFocus() tabImage = NSImage.alloc().initWithSize_(rep.size()) tabImage.addRepresentation_(rep) image = NSImage.alloc().initWithSize_(rep.size()) image.addRepresentation_(rep) image.lockFocus() tabImage.compositeToPoint_operation_fraction_(NSZeroPoint, NSCompositeSourceOver, 1.0) image.unlockFocus() return image
def dragImage(self): if self.cachedDragImage: return self.cachedDragImage self.lockFocus() rep = NSBitmapImageRep.alloc().initWithFocusedViewRect_(self.bounds()) self.unlockFocus() tabImage = NSImage.alloc().initWithSize_(rep.size()) tabImage.addRepresentation_(rep) image = NSImage.alloc().initWithSize_(rep.size()) image.addRepresentation_(rep) image.lockFocus() tabImage.drawAtPoint_fromRect_operation_fraction_( NSZeroPoint, NSZeroRect, NSCompositeSourceOver, 1.0) image.unlockFocus() return image
def refreshLibrary(self): if not self.history: return settings = SIPSimpleSettings() own_icon_path = settings.presence_state.icon selected_icon = None def md5sum(filename): md5 = hashlib.md5() with open(filename, 'rb') as f: for chunk in iter(lambda: f.read(128 * md5.block_size), b''): md5.update(chunk) return md5.hexdigest() if os.path.exists(self.storage_folder): files = os.listdir(self.storage_folder) else: files = [] array = NSMutableArray.array() knownFiles = set() for item in self.contentArrayController.arrangedObjects(): knownFiles.add(str(item.objectForKey_("path"))) seen_md5sum = {} i = 0 for f in files: if not f.startswith('user_icon') and not f.startswith( 'photo') and f != 'default_user_icon.tiff': continue p = os.path.normpath(self.storage_folder + "/" + f) if p not in knownFiles: photos_folder = unicodedata.normalize('NFC', self.storage_folder) filename = os.path.join(photos_folder, f) checksum = md5sum(filename) try: seen_md5sum[filename] except KeyError: seen_md5sum[filename] = checksum image = NSImage.alloc().initWithContentsOfFile_(p) if not image: continue item = NSDictionary.dictionaryWithObjectsAndKeys_( image, "picture", p, "path") array.addObject_(item) if own_icon_path is not None and filename == str( own_icon_path): selected_icon = i i += 1 if array.count() > 0: self.contentArrayController.addObjects_(array) if selected_icon is not None: self.libraryCollectionView.setSelectionIndexes_( NSIndexSet.indexSetWithIndex_(selected_icon))
def captureImage(self): if self.latestImageRep: imageRep = self.latestImageRep image = NSImage.alloc().initWithSize_(imageRep.size()) image.addRepresentation_(imageRep) image.setScalesWhenResized_(True) h = self.photoView.frame().size.height w = h * imageRep.size().width/imageRep.size().height image.setSize_(NSMakeSize(w, h)) self.photoView.setImage_(image)
def getCropped(self): image = self.image() cropped = NSImage.alloc().initWithSize_(self.cropRectangle.size) cropped.lockFocus() image.drawInRect_fromRect_operation_fraction_(NSMakeRect(0, 0, NSWidth(self.cropRectangle), NSHeight(self.cropRectangle)), self.cropRectangle, NSCompositeCopy, 1.0) cropped.unlockFocus() return cropped
def getCropped(self): image = self.image() cropped = NSImage.alloc().initWithSize_(self.cropRectangle.size) cropped.lockFocus() image.drawInRect_fromRect_operation_fraction_( NSMakeRect(0, 0, NSWidth(self.cropRectangle), NSHeight(self.cropRectangle)), self.cropRectangle, NSCompositeCopy, 1.0) cropped.unlockFocus() return cropped
def copy_img(self, image_data, mime='image/png', clear_first=True): image = NSImage.alloc().initWithData_(image_data) array = NSArray.arrayWithObject_(image) pb = NSPasteboard.generalPasteboard() if clear_first: pb.clearContents() # end def if mime in self.FORMAT_CONVERTER: pb.declareTypes_owner_([self._f(mime)], None) # end def success = pb.writeObjects_(array) return success # todo: throw
def makeDragImage(self): if self.delegate is None: return image = NSImage.alloc().initWithSize_(self.frame().size) image.lockFocus() frame = self.frame() frame.origin = NSZeroPoint rect = NSInsetRect(frame, 1.5, 1.5) if self.conferencing and not self.draggedOut: NSColor.selectedControlColor().colorWithAlphaComponent_(0.7).set() else: NSColor.whiteColor().colorWithAlphaComponent_(0.7).set() path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(rect, 5.0, 5.0) path.fill() if self.selected: path.setLineWidth_(3) NSColor.grayColor().set() else: path.setLineWidth_(1) NSColor.grayColor().set() path.stroke() NSColor.blackColor().set() point = NSMakePoint(8, NSMaxY(frame)-20) uri = format_identity_to_string(self.delegate.sessionController.remotePartyObject, check_contact=False, format='compact') NSString.stringWithString_(uri).drawAtPoint_withAttributes_(point, NSDictionary.dictionaryWithObjectsAndKeys_(NSFont.boldSystemFontOfSize_(12), NSFontAttributeName)) point = NSMakePoint(8, 6) if self.conferencing: NSString.stringWithString_(NSLocalizedString("Drop outside to remove from conference", "Audio session label")).drawAtPoint_withAttributes_(point, NSDictionary.dictionaryWithObjectsAndKeys_(NSFont.systemFontOfSize_(10), NSFontAttributeName)) else: audio_sessions = [sess.hasStreamOfType("audio") for sess in NSApp.delegate().contactsWindowController.sessionControllersManager.sessionControllers] if self.delegate.transferEnabled: text = NSLocalizedString("Drop this over a session or contact", "Audio session label") if len(audio_sessions) > 1 else NSLocalizedString("Drop this over a contact to transfer", "Audio session label") else: text = NSLocalizedString("Drop this over a session to conference", "Audio session label") NSString.stringWithString_(text).drawAtPoint_withAttributes_(point, NSDictionary.dictionaryWithObjectsAndKeys_(NSFont.systemFontOfSize_(10), NSFontAttributeName)) icon = NSImage.imageNamed_("NSEveryone") rect = frame s = icon.size() p = NSMakePoint(NSWidth(rect) - s.width - 8, rect.size.height - s.height - 8) r = NSMakeRect(0, 0, s.width, s.height) icon.drawAtPoint_fromRect_operation_fraction_(p, r, NSCompositeSourceOver, 0.5) image.unlockFocus() return image
def refreshLibrary(self): if not self.history: return settings = SIPSimpleSettings() own_icon_path = settings.presence_state.icon selected_icon = None def md5sum(filename): md5 = hashlib.md5() with open(filename,'rb') as f: for chunk in iter(lambda: f.read(128*md5.block_size), b''): md5.update(chunk) return md5.hexdigest() if os.path.exists(self.storage_folder): files = os.listdir(self.storage_folder) else: files = [] array = NSMutableArray.array() knownFiles = set() for item in self.contentArrayController.arrangedObjects(): knownFiles.add(unicode(item.objectForKey_("path"))) seen_md5sum = {} i = 0 for f in files: if not f.startswith('user_icon') and not f.startswith('photo') and f != 'default_user_icon.tiff': continue p = os.path.normpath(self.storage_folder + "/" + f) if p not in knownFiles: photos_folder = unicodedata.normalize('NFC', self.storage_folder) filename = os.path.join(photos_folder, f) checksum = md5sum(filename) try: seen_md5sum[filename] except KeyError: seen_md5sum[filename] = checksum image = NSImage.alloc().initWithContentsOfFile_(p) if not image: continue item = NSDictionary.dictionaryWithObjectsAndKeys_(image, "picture", p, "path") array.addObject_(item) if own_icon_path is not None and filename == unicode(own_icon_path): selected_icon = i i += 1 if array.count() > 0: self.contentArrayController.addObjects_(array) if selected_icon is not None: self.libraryCollectionView.setSelectionIndexes_(NSIndexSet.indexSetWithIndex_(selected_icon))
def buttonClicked_(self, sender): if sender.tag() == 20: # ch icon panel = NSOpenPanel.openPanel() panel.setTitle_(NSLocalizedString("Select Contact Icon", "Window title")) if panel.runModalForTypes_(NSArray.arrayWithObjects_("tiff", "png", "jpeg", "jpg")) == NSFileHandlingPanelOKButton: path = panel.filename() image = NSImage.alloc().initWithContentsOfFile_(path) self.photoImage.setImage_(image) elif sender.tag() == 21: # clear icon self.photoImage.setImage_(self.defaultPhotoImage) elif sender.tag() == 10: self.startDeallocTimer() NSApp.stopModalWithCode_(NSOKButton) else: self.startDeallocTimer() NSApp.stopModalWithCode_(NSCancelButton)
def updateIcon(self, icon): image = NSImage.alloc().initWithSize_(NSMakeSize(48,48)) image.lockFocus() size = icon.size() icon.drawAtPoint_fromRect_operation_fraction_(NSMakePoint((48-size.width)/2, (48-size.height)/2), NSMakeRect(0, 0, size.width, size.height), NSCompositeSourceOver, 1) # overlay file transfer direction icon if type(self.transfer) == OutgoingPushFileTransferHandler or (self.oldTransferInfo and self.oldTransferInfo.direction == "outgoing"): icon = NSImage.imageNamed_("outgoing_file") else: icon = NSImage.imageNamed_("incoming_file") icon.drawAtPoint_fromRect_operation_fraction_(NSMakePoint(2, 4), NSMakeRect(0, 0, size.width, size.height), NSCompositeSourceOver, 1) image.unlockFocus() self.icon.setImage_(image)
def showAboutPlugin_(self, sender): icon = None info = objc.currentBundle().infoDictionary() if 'CFBundleIconFile' in info: icon_file = info['CFBundleIconFile'] icon_path = objc.currentBundle().pathForImageResource_(icon_file) if icon_path is not None: icon = NSImage.alloc().initWithContentsOfFile_(icon_path) if icon is None: icon = NSImage.imageNamed_('NSApplicationIcon') options = {'Credits': NSAttributedString.alloc().initWithString_('ÇFULLUSERNAMEÈ'), 'ApplicationName': self.name(), 'ApplicationIcon': icon, 'ApplicationVersion': info['CFBundleShortVersionString'], 'Version': 'Coda %s' % NSBundle.mainBundle().infoDictionary()['CFBundleShortVersionString']} NSApp.orderFrontStandardAboutPanelWithOptions_(options)
def captureImage(self): if self.latestImageRep: imageRep = self.latestImageRep image = NSImage.alloc().initWithSize_(imageRep.size()) image.addRepresentation_(imageRep) image.setScalesWhenResized_(True) h = 160 w = h * imageRep.size().width/imageRep.size().height image.setSize_(NSMakeSize(w, h)) self.photoView.setImage_(image) parent = self.photoView.superview().frame() x = (NSWidth(parent)-w) / 2 y = NSHeight(parent) - h - 12 self.photoView.setFrame_(NSMakeRect(x, y, w, h))
def capture_handler(sampleBuffer): if not sampleBuffer: NotificationCenter().post_notification('CameraSnapshotDidFail', sender=self) return imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) if not imageBuffer: NotificationCenter().post_notification('CameraSnapshotDidFail', sender=self) return CVBufferRetain(imageBuffer) imageRep = NSCIImageRep.imageRepWithCIImage_(CIImage.imageWithCVImageBuffer_(imageBuffer)) image = NSImage.alloc().initWithSize_(imageRep.size()) image.addRepresentation_(imageRep) CVBufferRelease(imageBuffer) NotificationCenter().post_notification('CameraSnapshotDidSucceed', sender=self, data=NotificationData(image=image))
def getButtonImageForState(self, size, pushed): image = NSImage.alloc().initWithSize_(size) image.lockFocus() rect = NSMakeRect(1, 1, size.width-1, size.height-1) NSColor.clearColor().set() NSRectFill(rect) try: NSColor.blackColor().set() path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(rect, 8.0, 8.0) path.fill() path.setLineWidth_(2) NSColor.grayColor().set() path.stroke() finally: image.unlockFocus() return image
def awakeFromNib(self): smileys = SmileyManager().get_smiley_list() menu = self.smileyButton.menu() while menu.numberOfItems() > 0: menu.removeItemAtIndex_(0) bigText = NSAttributedString.alloc().initWithString_attributes_(" ", NSDictionary.dictionaryWithObject_forKey_(NSFont.systemFontOfSize_(16), NSFontAttributeName)) for text, file in smileys: image = NSImage.alloc().initWithContentsOfFile_(file) if not image: print "cant load %s"%file continue image.setScalesWhenResized_(True) image.setSize_(NSMakeSize(16, 16)) atext = bigText.mutableCopy() atext.appendAttributedString_(NSAttributedString.alloc().initWithString_(text)) item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(text, "insertSmiley:", "") menu.addItem_(item) item.setTarget_(self) item.setAttributedTitle_(atext) item.setRepresentedObject_(NSAttributedString.alloc().initWithString_(text)) item.setImage_(image)
def updateIcon(self, icon): image = NSImage.alloc().initWithSize_(NSMakeSize(48, 48)) image.lockFocus() size = icon.size() icon.drawAtPoint_fromRect_operation_fraction_( NSMakePoint((48 - size.width) / 2, (48 - size.height) / 2), NSMakeRect(0, 0, size.width, size.height), NSCompositeSourceOver, 1) # overlay file transfer direction icon if type(self.transfer) == OutgoingPushFileTransferHandler or ( self.oldTransferInfo and self.oldTransferInfo.direction == "outgoing"): icon = NSImage.imageNamed_("outgoing_file") else: icon = NSImage.imageNamed_("incoming_file") icon.drawAtPoint_fromRect_operation_fraction_( NSMakePoint(2, 4), NSMakeRect(0, 0, size.width, size.height), NSCompositeSourceOver, 1) image.unlockFocus() self.icon.setImage_(image)
def storeCaptured(self): makedirs(self.storage_folder) dt = datetime.datetime.now().strftime("%Y%m%d%H%M%S") if not self.photoView.image(): self.captureImage() if self.high_res: imageRep = self.latestImageRep image = NSImage.alloc().initWithSize_(imageRep.size()) image.addRepresentation_(imageRep) else: image = self.photoView.getCropped() tiff_data = image.TIFFRepresentation() path = self.storage_folder + "/photo%s.png" % dt bitmap_data = NSBitmapImageRep.alloc().initWithData_(tiff_data) png_data = bitmap_data.representationUsingType_properties_(NSPNGFileType, None) data = png_data.bytes().tobytes() with open(path, 'w') as f: f.write(data) self.refreshLibrary() return path, image
def makeDragImage(self): if self.delegate is None: return image = NSImage.alloc().initWithSize_(self.frame().size) image.lockFocus() frame = self.frame() frame.origin = NSZeroPoint rect = NSInsetRect(frame, 1.5, 1.5) if self.conferencing and not self.draggedOut: NSColor.selectedControlColor().colorWithAlphaComponent_(0.7).set() else: NSColor.whiteColor().colorWithAlphaComponent_(0.7).set() path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_( rect, 5.0, 5.0) path.fill() if self.selected: path.setLineWidth_(3) NSColor.grayColor().set() else: path.setLineWidth_(1) NSColor.grayColor().set() path.stroke() NSColor.blackColor().set() point = NSMakePoint(8, NSMaxY(frame) - 20) uri = format_identity_to_string( self.delegate.sessionController.remoteIdentity, check_contact=False, format='compact') NSString.stringWithString_(uri).drawAtPoint_withAttributes_( point, NSDictionary.dictionaryWithObjectsAndKeys_( NSFont.boldSystemFontOfSize_(12), NSFontAttributeName)) point = NSMakePoint(8, 6) if self.conferencing: NSString.stringWithString_( NSLocalizedString( "Drop outside to remove from conference", "Audio status label")).drawAtPoint_withAttributes_( point, NSDictionary.dictionaryWithObjectsAndKeys_( NSFont.systemFontOfSize_(10), NSFontAttributeName)) else: audio_sessions = [ sess.hasStreamOfType("audio") for sess in NSApp.delegate().contactsWindowController. sessionControllersManager.sessionControllers ] if self.delegate.transferEnabled: text = NSLocalizedString( "Drop this over a session or contact", "Audio status label" ) if len(audio_sessions) > 1 else NSLocalizedString( "Drop this over a contact to transfer", "Audio status label") else: text = NSLocalizedString( "Drop this over a session to conference", "Audio status label") NSString.stringWithString_(text).drawAtPoint_withAttributes_( point, NSDictionary.dictionaryWithObjectsAndKeys_( NSFont.systemFontOfSize_(10), NSFontAttributeName)) icon = NSImage.imageNamed_("NSEveryone") rect = frame s = icon.size() p = NSMakePoint( NSWidth(rect) - s.width - 8, rect.size.height - s.height - 8) r = NSMakeRect(0, 0, s.width, s.height) icon.drawAtPoint_fromRect_operation_fraction_(p, r, NSCompositeSourceOver, 0.5) image.unlockFocus() return image
from AppKit import NSPasteboard, NSPasteboardTypePDF, NSTIFFPboardType, NSPICTPboardType from Foundation import NSURL, NSImage import Quartz as Quartz import os, syslog # Change this to whatever filepath you want: outfile=os.path.expanduser("~/Desktop/Clipboard.pdf") myFavoriteTypes = [NSPasteboardTypePDF, NSTIFFPboardType, NSPICTPboardType, 'com.adobe.encapsulated-postscript'] pb = NSPasteboard.generalPasteboard() best_type = pb.availableTypeFromArray_(myFavoriteTypes) if best_type: clipData = pb.dataForType_(best_type) if clipData: image = NSImage.alloc().initWithPasteboard_(pb) if image: page = Quartz.PDFPage.alloc().initWithImage_(image) if os.path.exists(outfile): pdfURL = NSURL.fileURLWithPath_(outfile) myFile = Quartz.PDFDocument.alloc().initWithURL_(pdfURL) if myFile: pagenum = myFile.pageCount() myFile.insertPage_atIndex_(page, pagenum) print "Image added to Clipboard file." else: pageData = page.dataRepresentation() myFile = Quartz.PDFDocument.alloc().initWithData_(pageData) myFile.writeToFile_(outfile) print "Clipboard file created."