view unixSoft/bin/apply-patchbomb @ 266:93a8f55a4e30

xmonad: add takeTopFocus logHook This is required to make IntelliJ (and supposedly all other Swing applications) properly notice that they've recieved the focus. According to [0], the problem is that "xmonad does not follow ICCCM and ignores WM_TAKE_FOCUS protocol", but the patches on that ticket haven't yet been accepted, so the function was added to xmonad-contrib as a workaround until something happens in xmonad proper. [0]: http://code.google.com/p/xmonad/issues/detail?id=177
author Augie Fackler <durin42@gmail.com>
date Wed, 02 Nov 2011 09:53:57 -0500
parents e8170eba88cd
children 4b661cede8ad
line wrap: on
line source

#!/usr/bin/python
# shebang for system python explicitly so we're sure to have pyobjc and
# the scripting bridge.
"""apply-patchbomb: apply selected messages in Mail.app to an hg repo in pwd.

This uses the scripting bridge to talk to Mail and subprocess to pass the
patch to Mercurial on stdin.
"""
import email
import subprocess
import sys

import ScriptingBridge

def main():
    mail = ScriptingBridge.SBApplication.applicationWithBundleIdentifier_(
        'com.apple.Mail')
    messages = list(sorted(mail.selection(),
                           cmp=lambda x,y: cmp(x.subject(), y.subject())))
    for m in messages:
        print 'Applying', m.subject()
        p = subprocess.Popen(['hg', 'import', '-'], stdin=subprocess.PIPE)
        p.stdin.write(m.source())
        p.stdin.close()
        if p.wait() != 0:
            print 'hg import failed, bailing'
            return 2
    return 0

if __name__ == '__main__':
    sys.exit(main())