Removing field from all entries in address book

Discussion in 'Mac Programming' started by uplusd, Mar 5, 2010.

  1. uplusd macrumors 6502

    Joined:
    Apr 8, 2008
    Location:
    Silicon Valley
    #1
    Hi,

    Is there a way I can remove the 'homepage' field from all contacts in my address book? The sync on the iphone's facebook app added all these fb://xxxxx entries to all my address book contacts.

    Thanks!
     
  2. swiftaw macrumors 603

    swiftaw

    Joined:
    Jan 31, 2005
    Location:
    Omaha, NE, USA
    #2
    Did you try Address Book->Preferences->Template?
     
  3. uplusd thread starter macrumors 6502

    Joined:
    Apr 8, 2008
    Location:
    Silicon Valley
    #3
    That's the template for creating new contacts. I don't think it will edit existing contacts.
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    You might be able to pull it off with Automator. I'm not at my mac to see what options it has for Address Book. AppleScript could do it too, but you'd have to figure out the code for it. Here's one for removing duplicate entries. it could be a decent starting point.
     
  5. -aggie- macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #5
    Try this:

    Code:
    tell application "Address Book" 
         repeat with this_person in every person 
            repeat with this_homepage in every Homepage of this_person 
                    remove this_homepage from Homepage of this_person 
            end repeat 
         end repeat 
     end tell
    I'm not totally sure about the "Homepage" field (it could be homepage), but it's what I saw on the net. I'd backup Address Book before running.

    This is what happens when you give advice from work and you don't have a Mac at work. :)
     
  6. uplusd thread starter macrumors 6502

    Joined:
    Apr 8, 2008
    Location:
    Silicon Valley
    #6
    Thanks for that! I tried running the script with both 'Homepage' and 'homepage' but got error: expected class name but found identifier
     
  7. -aggie- macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #7
    Comment out (using --) the repeat/end repeat that used the Homepage part to make sure the error is with Homepage and I'll try to find the field name somewhere on the internet.

    Code:
            --repeat this_homepage in every Homepage of this_person 
                    --remove this_homepage from Homepage of this_person 
            --end repeat 
     
  8. uplusd thread starter macrumors 6502

    Joined:
    Apr 8, 2008
    Location:
    Silicon Valley
    #8
    Commented out and script runs with no error
     
  9. -aggie- macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #9
    That means the Homepage field is the problem. Still looking.

    BTW, when you look at the Address Book, what is the part with the web page called? That might help.
     
  10. uplusd thread starter macrumors 6502

    Joined:
    Apr 8, 2008
    Location:
    Silicon Valley
    #10
    [​IMG]

    looks like its 'homepage' hehe
     
  11. -aggie- macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #11
    Well that sucks. Try URL. Or try homepage again. Still haven't found anything definitive.

    Edit: Also try url. I found some evidence of that being used for URL's in Applescript. I'll look at the Address Book plist tonight, if no one else comes to help.
     
  12. uplusd thread starter macrumors 6502

    Joined:
    Apr 8, 2008
    Location:
    Silicon Valley
    #12
    Here is the error message using 'url' and 'URL'. It doesn't seem to be case sensitive as it changes URL to url:

    error "Address Book got an error: Can’t get url of item 1 of every person." number -1728 from url of item 1 of every person
     
  13. -aggie- macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #13
    Comment out the same repeat and end repeat and replace the middle line with:

    remove url of this_person
     
  14. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #14
    url is a keyword in AppleScript, but doesn't relate to the URL associated with a contact. In AppleScript, under the File menu there's a dictionary item, which allows you to open the AppleScript dictionary for Address Book. From there I saw it's the 'home page' that you need to refer to. I've been trying it in the script, but it hasn't completely worked yet for the whole process, but I don't have many contacts with web pages, so that could be part of it.
     
  15. -aggie- macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #15

    I'm still on windows here. Did you change it to my post above.
    Replacing url with home page.
     
  16. uplusd thread starter macrumors 6502

    Joined:
    Apr 8, 2008
    Location:
    Silicon Valley
    #16
    This is what I have right now:

    Code:
    tell application "Address Book"
    	repeat with this_person in every person
    		--repeat with this_homepage in every url of this_person
    		remove home page of this_person
    		--end repeat
    	end repeat
    end tell
    Is that corret? If so, I get: error "Address Book got an error: Some parameter is missing for remove." number -1701
     
  17. -aggie- macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #17
    I was going by the poster above who said use home page. Change home page back to url and see what happens. Also, maybe url of home page?
     
  18. uplusd thread starter macrumors 6502

    Joined:
    Apr 8, 2008
    Location:
    Silicon Valley
    #18
    No go :( I can wait until you get home to try it out, no rush.

    btw thanks for all your help!
     
  19. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #19
    Well, it appears Address Book uses home page, urls, and url depending on the context. Good grief. Anyways, here's a close solution. I was able to print each one out as a test. I commented out a line that should set it to an empty string, which should serve the same purpose as deleting it, but so far it doesn't work.

    PHP:
    tell application "Address Book"
        
    set output to ""
        
    repeat with this_person in every person
            set numurl to count 
    (urls of this_person)
            if 
    numurl 0 then
                set theurls to properties of urls of this_person
                repeat with this_url in theurls
                    
    -- Capturing the urls and new line
                    set output to output 
    & (value of this_url as string) & return
                    -- 
    Remove this url
                    
    --set value of this_url to ""
                
    end repeat
            end 
    if
        
    end repeat
        display dialog output
    end tell
     
  20. -aggie- macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #20
    Where are you finding that info? I just looked at Address Book and it looked like the field was homepage with label URL to go in it.
     
  21. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #21
    I'll attach a screen shot of the dictionary. I've got a script that runs and says it's deleting things, but in Address Book, the urls are still there.
     

    Attached Files:

  22. -aggie- macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #22
    That looks good. I'm not sure why it's not working either. I'm going to keep playing with it to see what's up. BTW, thanks for helping on this.

    Off topic, but do you know where the data for Address Book is on OSX?
     
  23. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #23
    Looks to be ~/Library/Application Support/AddressBook/

    The Metadata folder seems to hold individual vCard type data for each entry, but the AddressBook-v00.abcddb, which is a SQLite 3 database file may hold current info. Using a SQLite browser I can see the data in it. Using it all the URLs can be deleted. Definitely would want to make a backup before doing so just in case it breaks anything.

    I'm using SQLite Database Browser 1.3 to browse the file. The table to look at is ZABCDURLADDRESS.
     
  24. -aggie- macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #24
    I already had SQLite DB. I use it for doing stuff with the iPhone. For some reason when I searched for AddressBook in Spotlight, that folder didn't show up. Anyway, you're right, that is the one. It had all 5 of my url's in it. I wanted to know where it was so I could make a copy before messing with it.
     
  25. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #25
    Address Book has an Export option in the File menu that makes it easier to do a backup. That's what I did before running all the AppleScript stuff. Still haven't found a way to get the AppleScript technique to work, but editing the SQLite DB directly does work at least.
     

Share This Page