From 881aed35576be8a35a33ed1c6ebde06a2d9722cf Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Wed, 21 Oct 2009 22:44:59 +0300 Subject: Initial commit --- batchdmg.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 batchdmg.py diff --git a/batchdmg.py b/batchdmg.py new file mode 100644 index 0000000..63570ff --- /dev/null +++ b/batchdmg.py @@ -0,0 +1,40 @@ +""" + batchdmg.py + Batch-create DMG files from mounted media + @author Filipp Lepalaan + @created 20.10.2009 + @updated 21.10.2009 + http://developer.apple.com/cocoa/pyobjc.html + NSRunLoop must be used instead of threads or forking +""" +import sys, time +from AppKit import * +from subprocess import Popen + +class Imager(NSObject): + def init(self): + nc = NSWorkspace.sharedWorkspace().notificationCenter() + nc.addObserver_selector_name_object_(self, "observeCenter:", "NSWorkspaceDidMountNotification", None) + print "Waiting for media..." + + def observeCenter_(self, notification): + ui = notification.userInfo() + path = ui['NSDevicePath'].encode("utf-8") + name = ui['NSWorkspaceVolumeLocalizedNameKey'].encode("utf-8") + util = "/usr/bin/hdiutil" + print " - imaging '%s'" % (name) + cmd = [util, "create", "-format", "UDBZ", "-srcfolder", path, name+".dmg"] + + Popen(cmd, shell=False).communicate() + Popen([util, "eject", "-quiet", path], shell=False).communicate() + + print "Ejecting '%s'" % (name) + print "Waiting for media..." + + def dealloc(self): + nc = NSWorkspace.sharedWorkspace().notificationCenter() + nc.removeObserver_(self) + +rl = NSRunLoop.currentRunLoop() +s = Imager.alloc().init() +rl.run() \ No newline at end of file -- cgit v1.2.3