# coding: utf-8 # https://gist.github.com/lukaskollmer/52a20e8d6447b1fe6033f95386405c27 import contacts import ui from datetime import datetime import operator import console console.clear() if not contacts.is_authorized(): print 'You need to allow acces to contacts to use this application' def load_upcoming_birthdays(pretty_output=True, leading_zeros=False): all_contacts = contacts.get_all_people() all_birthdays = [] all_output = [] number_of_contacts_without_birthday = 0 now = datetime.now() for person in all_contacts: if person.kind == 0: #0: Person, 1: company if person.birthday: birthday = person.birthday next_birthday = datetime(now.year, birthday.month, birthday.day) if next_birthday < now:
# @omz # https://forum.omz-software.com/topic/2734/contacts-module-access-profile-picture/4 from objc_util import * from ctypes import string_at import contacts import ui import photos # CHANGE THIS: CONTACT_NAME = 'John Doe' # Easier to do the authorization with the contacts module (this also authorizes the Contacts.framework): if not contacts.is_authorized(): # This implicitly shows the permission dialog, if necessary: contacts.get_all_groups() # Load classes we need from Contacts.framework: NSBundle.bundleWithPath_('/System/Library/Frameworks/Contacts.framework').load() CNContactStore = ObjCClass('CNContactStore') CNContact = ObjCClass('CNContact') CNSaveRequest = ObjCClass('CNSaveRequest') def main(): store = CNContactStore.alloc().init().autorelease() # Find the first contact that matches the name. pred = CNContact.predicateForContactsMatchingName_(CONTACT_NAME) fetch_keys = ['imageDataAvailable', 'imageData'] people = store.unifiedContactsMatchingPredicate_keysToFetch_error_(pred, fetch_keys, None)