Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Sync only Address Book entries with phone numbers to iPhone iOS devices
I used to have a mobile phone which I synced all the time with iSync, where there was an option to only sync contacts with phone numbers. After getting an iPhone, I noticed this didn't exist. So why not use a Smart Group to do the job? Because they don't sync with the iPhone. But I also wanted everyone's emails and other details.

So I wrote up an AppleSript that updates a regular Address Book group with only people who have phone numbers. This worked great, then after a while, I wanted some numbers to not show up (people you want to keep in your phone but will never call, or whose name you don't want to see every time you scroll down your list). I created a group called Not Phone, and modified my script so that they are removed from the Phone group.

This script will create the groups for you. Warning: if you have a group called Phone already in existence, I suggest renaming the group (or changing the group name that the script uses in the first line), as that group will be modified. Here's the code:
property thePhoneGroup : "Phone"
property theNotPhoneGroup : "Not Phone"
on createGroup(str)
  tell application "Address Book"
    try
      get group str
    on error
      make new group with properties {name:str}
      save
    end try
  end tell
end createGroup

tell application "Address Book"
  my createGroup(thePhoneGroup)
  my createGroup(theNotPhoneGroup)
    
  set allContacts to every person
  
  repeat with p in allContacts
    if (count of phone of p) is 0 then
      -- Dont have a number
      -- if they are in the group then remove them
      if (name of groups of p contains thePhoneGroup) then remove p from group thePhoneGroup
    else
      -- They have a number, add to the group
      if (name of groups of p does not contain thePhoneGroup) then
        add p to group thePhoneGroup
      end if
      if (name of groups of p contains thePhoneGroup and name of groups of p contains theNotPhoneGroup) then remove p from group thePhoneGroup
    end if
  end repeat
  save
end tell
So now I can just leave the iPhone set to sync the Phone group, and I have no problems.

[robg adds: This worked as described for me in OS X 10.5.]
    •    
  • Currently 1.69 / 5
  You rated: 3 / 5 (13 votes cast)
 
[14,669 views]  

Sync only Address Book entries with phone numbers to iPhone | 6 comments | Create New Account
Click here to return to the 'Sync only Address Book entries with phone numbers to iPhone' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Sync only Address Book entriess with phone numbers to iPhone
Authored by: Fofer on Oct 23, '09 08:49:36AM

Great tip. Unfortunately, those of us who sync wirelessly with MobileMe don't have the ability to select which Address Book groups to sync... it's all or nothing. (Same with calendars.) Only with USB synching can you select which groups/calendars to sync. I hope Apple addresses this in a MobileMe update one day.



[ Reply to This | # ]
MobileMe failures
Authored by: Krioni on Oct 25, '09 06:44:29PM

I hope so, too. I'm very frustrated that I'm paying for something that Apple is so lazy about improving.

---
http://www.danshockley.com



[ Reply to This | # ]
Sync only Address Book entriess with phone numbers to iPhone
Authored by: InSearch on Nov 11, '09 06:48:33AM
You can try some software to synchronize only certain Address Book groups. There are some nice free programs, I run SyncMate, for example.

[ Reply to This | # ]
Sync only Address Book entriess with phone numbers to iPhone
Authored by: bobme on Oct 23, '09 09:17:52PM

I guess this hint is for people who don't use email on their iPhones?



[ Reply to This | # ]
Sync only Address Book entriess with phone numbers to iPhone
Authored by: bigkm on Oct 25, '09 09:51:23PM

It works with mobile me.

I just leave the Phone.app in the group phone and it all works fine.



[ Reply to This | # ]
a strange non-optimization comment
Authored by: Krioni on Oct 25, '09 06:33:06PM

NOTE: This comment (below) is _NOT_ something you should use to modify the original hint.

I took a look at how you could ask Address Book to give you a list of people who have phones (using the AppleScript command 'whose'), rather than having to loop over every contact. Unfortunately (but not really that surprising), Address Book is MUCH slower at doing that filtering up front than it is at looping over each person separately.

So, the code shown below is for informational purposes only - it would much the script much slower:

set phoneContacts to every person whose (value of first phone of it) is not missing value

Now, this takes about 20 seconds to run on my Address Book database of about 1000 contacts. When I tested the original code, the loop-over-all-contacts takes about 1 second.

I thought at first that it would be faster to just get the list of people you actually want, but, as is often the case in AppleScript, the 'whose' command fails amazingly here. I originally was going to post this alternative code without testing, but based on past experiences, I thought it would be good to know how well the original code ran. The result? Original code in the hint is 20 times faster. Wow.

Aside: A similarly slow command that would get only people who have no phones:

set phoneContacts to every person whose (value of first phone of it) is missing value

AppleScript is a strange beast - this is by far not the strangest thing I've seen over the years.

---
http://www.danshockley.com


[ Reply to This | # ]