Last active
August 29, 2015 14:13
-
-
Save dalleng/1879263215191e3df6e7 to your computer and use it in GitHub Desktop.
Saves the icon of a running app with a given pid
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 sys | |
from Cocoa import NSDictionary, NSNumber | |
from AppKit import NSRunningApplication, NSImageCompressionFactor, NSBitmapImageRep, NSPNGFileType | |
app = NSRunningApplication.runningApplicationWithProcessIdentifier_(int(sys.argv[1])) | |
icon = app.icon() | |
image_data = icon.TIFFRepresentation() | |
image_rep = NSBitmapImageRep.imageRepWithData_(image_data) | |
image_props = NSDictionary.dictionaryWithObject_forKey_(NSNumber.numberWithFloat_(1.0), NSImageCompressionFactor) | |
image_data = image_rep.representationUsingType_properties_(NSPNGFileType, image_props) | |
file_name = "{}.png".format(app.localizedName()) | |
image_data.writeToFile_atomically_(file_name, False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment