Python Address Label

A PyObjC Example without documentation


This plugin adds an 'Python Address Label' action to "Address" properties in
the AddressBook application.

To install this plugin you have to build it (using 'python py2app')
and then copy it to  '~/Library/Address Book Plug-Ins' (this folder may
not exist yet.
from AddressBook import kABAddressProperty
from AppKit import NSNull, NSObject, NSStringPboardType, NSPasteboard

class PyAddressLabelDelegate(NSObject):
    def actionProperty(self):
        return kABAddressProperty

    def titleForPerson_identifier_(self, person, identifier):
        return "Python Address Label"

    def shouldEnableActionForPerson_identifier_(self, person, identifier):
        return len(person.address()) > 0

    def performActionForPerson_identifier_(self, person, identifier):
        text =
        if person.department() is not NSNull.null():
            text += "\n" + person.department()

        if person.organization() is not NSNull.null():
            text += "\n" + person.organization()

        address = person.address()[0]
        text += "\n" + address.street()
        text += "\n" + + " " +

        if is not NSNull.null():
            text += "\n" +

        pboard = NSPasteboard.generalPasteboard()
        pboard.declareTypes_owner_([NSStringPboardType], None)
        pboard.setString_forType_(text, NSStringPboardType)

Script for building the example.

    python3 py2app

To use this copy dist/PyAddressLabel.plugin to the plugin directory:
   $ mv dist/PyAddressLabel.plugin ~/Library/"Address Book Plug-Ins/PyAddressLabel.plugin"
from setuptools import setup

infoPlist = {
    "CFBundleName": "PyAddressLabel",
    "CFBundleGetInfoString": "Silly PopUp for AddressBook",
    "CFBundleVersion": "0.1",
    "CFBundleShortVersionString": "0.1",
    "NSPrincipalClass": "PyAddressLabelDelegate",

    setup_request=["py2app", "pyobjc-framework-AddressBook", "pyobjc-framework-Cocoa"],
    options={"py2app": {"extension": ".bundle", "plist": infoPlist}},