Last active
October 24, 2015 23:42
-
-
Save rjames86/fbba26662c95a558e8af to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // Use the TextExpander object to appendOutput() or adjust date and time, | |
| // or just use the final statement as the snippet's expansion value, e.g. | |
| ObjC.import('stdio') | |
| ObjC.import("AddressBook"); | |
| meRecord = $.ABAddressBook.sharedAddressBook.me | |
| //emails = meRecord.valueForProperty($.kABEmailProperty) | |
| var propertyToObjCType = { | |
| 'email': $.kABEmailProperty, | |
| 'address': $.kABAddressProperty | |
| } | |
| var labelToObjCType = { | |
| 'work': $.kABWorkLabel, | |
| 'home': $.kABHomeLabel, | |
| } | |
| function valueForProperty(property){ | |
| return meRecord.valueForProperty(propertyToObjCType[property]) | |
| } | |
| function getEmailByLabel(inputLabel){ | |
| emails = valueForProperty('email') | |
| label = labelToObjCType[inputLabel] | |
| for (var i = 0; i < emails.count; i++){ | |
| if ($.CFEqual(emails.labelAtIndex(i), label)){ | |
| return emails.valueAtIndex(i) | |
| } | |
| } | |
| } | |
| function getAddressByLabel(inputLabel){ | |
| addresses = valueForProperty('address') | |
| label = labelToObjCType[inputLabel] | |
| for (var i = 0; i < addresses.count; i++){ | |
| if ($.CFEqual(addresses.labelAtIndex(i), label)){ | |
| return addresses.valueAtIndex(i) | |
| } | |
| } | |
| } | |
| // Yay! This works for pretty printing addresses | |
| $.ABAddressBook.sharedAddressBook.formattedAddressFromDictionary(getAddressByLabel('work')).string | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment