Last active
          October 24, 2015 23:42 
        
      - 
      
- 
        Save rjames86/fbba26662c95a558e8af to your computer and use it in GitHub Desktop. 
Revisions
- 
        Ryan M revised this gist Oct 24, 2015 . 1 changed file with 14 additions and 1 deletion.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -14,12 +14,14 @@ meRecord = sAB.me var propertyToObjCType = { 'email': $.kABEmailProperty, 'address': $.kABAddressProperty, 'phone': $.kABPhoneProperty } var labelToObjCType = { 'work': $.kABWorkLabel, 'home': $.kABHomeLabel, 'iPhone': $.kABPhoneiPhoneLabel, } function valueForProperty(property){ @@ -47,3 +49,14 @@ function getAddressByLabel(inputLabel){ } } function getPhoneByLabel(inputLabel){ phone = valueForProperty('phone') label = labelToObjCType[inputLabel] for (var i = 0; i < phone.count; i++){ if ($.CFEqual(phone.labelAtIndex(i), label)){ return phone.valueAtIndex(i) } } } 
- 
        Ryan M revised this gist Oct 24, 2015 . 1 changed file with 1 addition and 10 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -8,8 +8,6 @@ https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/ */ ObjC.import("AddressBook"); sAB = $.ABAddressBook.sharedAddressBook meRecord = sAB.me @@ -28,7 +26,6 @@ function valueForProperty(property){ return meRecord.valueForProperty(propertyToObjCType[property]) } function getEmailByLabel(inputLabel){ emails = valueForProperty('email') label = labelToObjCType[inputLabel] @@ -45,14 +42,8 @@ function getAddressByLabel(inputLabel){ label = labelToObjCType[inputLabel] for (var i = 0; i < addresses.count; i++){ if ($.CFEqual(addresses.labelAtIndex(i), label)){ return sAB.formattedAddressFromDictionary(addresses.valueAtIndex(i)).string } } } 
- 
        Ryan M revised this gist Oct 24, 2015 . 1 changed file with 14 additions and 9 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,18 @@ /* References: http://www.macdevcenter.com/pub/a/mac/2002/08/27/cocoa.html?page=2 https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/AddressBook/Tasks/AccessingData.html#//apple_ref/doc/uid/20001023-BABHHIHC */ ObjC.import('stdio') ObjC.import("AddressBook"); sAB = $.ABAddressBook.sharedAddressBook meRecord = sAB.me var propertyToObjCType = { 'email': $.kABEmailProperty, @@ -40,14 +45,14 @@ function getAddressByLabel(inputLabel){ label = labelToObjCType[inputLabel] for (var i = 0; i < addresses.count; i++){ if ($.CFEqual(addresses.labelAtIndex(i), label)){ sAB.formattedAddressFromDictionary(addresses.valueAtIndex(i)).string } } } 
- 
        Ryan M revised this gist Oct 24, 2015 . 1 changed file with 7 additions and 14 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,14 @@ // 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 @@ -50,11 +46,8 @@ function getAddressByLabel(inputLabel){ } // Yay! This works for pretty printing addresses $.ABAddressBook.sharedAddressBook.formattedAddressFromDictionary(getAddressByLabel('work')).string 
- 
        Ryan M revised this gist Oct 24, 2015 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -55,3 +55,6 @@ function getAddressByLabel(inputLabel){ // This will return the strings for certain parts of the address // Not sure if there's a way to have it pretty print a full address ObjC.unwrap(getAddressByLabel('home').objectForKey($.kABAddressCityKey)) + "\n" + ObjC.unwrap(getAddressByLabel('home').objectForKey($.kABAddressStateKey)) // this *should* do it, but just returns [id NSConcreteMutableAttributedString] $.ABAddressBook.sharedAddressBook.formattedAddressFromDictionary(getAddressByLabel('home')) 
- 
        Ryan M revised this gist Oct 24, 2015 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -13,8 +13,6 @@ ObjC.import("AddressBook"); meRecord = $.ABAddressBook.sharedAddressBook.me var propertyToObjCType = { 'email': $.kABEmailProperty, 'address': $.kABAddressProperty 
- 
        Ryan M revised this gist Oct 24, 2015 . No changes.There are no files selected for viewing
- 
        Ryan M revised this gist Oct 24, 2015 . 1 changed file with 38 additions and 10 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -8,24 +8,52 @@ https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/ */ 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) } } } // Work in progress // This will return the strings for certain parts of the address // Not sure if there's a way to have it pretty print a full address ObjC.unwrap(getAddressByLabel('home').objectForKey($.kABAddressCityKey)) + "\n" + ObjC.unwrap(getAddressByLabel('home').objectForKey($.kABAddressStateKey)) 
- 
        Ryan M revised this gist Oct 24, 2015 . 1 changed file with 19 additions and 0 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,13 @@ /* References: http://www.macdevcenter.com/pub/a/mac/2002/08/27/cocoa.html?page=2 https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/AddressBook/Tasks/AccessingData.html#//apple_ref/doc/uid/20001023-BABHHIHC */ ObjC.import("AddressBook"); meRecord = $.ABAddressBook.sharedAddressBook.me @@ -10,3 +20,12 @@ for (var i = 0; i < emails.count; i++){ emails.valueAtIndex(i) } } // returns the email labeled as Work in your Contacts.app record for (var i = 0; i < emails.count; i++){ if ($.CFEqual(emails.labelAtIndex(i), $.kABWorkLabel)){ emails.valueAtIndex(i) } } 
- 
        Ryan M revised this gist Oct 24, 2015 . 1 changed file with 0 additions and 4 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,6 @@ ObjC.import("AddressBook"); meRecord = $.ABAddressBook.sharedAddressBook.me emails = meRecord.valueForProperty($.kABEmailProperty) 
- 
        Ryan M revised this gist Oct 24, 2015 . 1 changed file with 1 addition and 4 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,14 @@ ObjC.import("AddressBook"); meRecord = $.ABAddressBook.sharedAddressBook.me function getNormalizedLabel(element){ return $.ABLocalizedPropertyOrLabel(element) } emails = meRecord.valueForProperty($.kABEmailProperty) // returns the email labeled as Home in your Contacts.app record for (var i = 0; i < emails.count; i++){ if ($.CFEqual(emails.labelAtIndex(i), $.kABHomeLabel)){ emails.valueAtIndex(i) 
- 
        Ryan M created this gist Oct 24, 2015 .There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ ObjC.import("AddressBook"); meRecord = $.ABAddressBook.sharedAddressBook.me function getNormalizedLabel(element){ return $.ABLocalizedPropertyOrLabel(element) } emails = meRecord.valueForProperty($.kABEmailProperty) //label = emails.labelAtIndex(0) //$.CFEqual(label, $.kABHomeLabel) for (var i = 0; i < emails.count; i++){ if ($.CFEqual(emails.labelAtIndex(i), $.kABHomeLabel)){ emails.valueAtIndex(i) } } 
 Ryan M
              revised
            
            this gist
            
              Ryan M
              revised
            
            this gist