Removing field from all entries in address book

uplusd

macrumors 6502
Original poster
Apr 8, 2008
276
0
Silicon Valley
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!
 

-aggie-

macrumors P6
Jun 19, 2009
16,793
50
Where bunnies are welcome.
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. :)
 

uplusd

macrumors 6502
Original poster
Apr 8, 2008
276
0
Silicon Valley
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. :)
Thanks for that! I tried running the script with both 'Homepage' and 'homepage' but got error: expected class name but found identifier
 

-aggie-

macrumors P6
Jun 19, 2009
16,793
50
Where bunnies are welcome.
Thanks for that! I tried running the script with both 'Homepage' and 'homepage' but got error: expected class name but found identifier
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
 

uplusd

macrumors 6502
Original poster
Apr 8, 2008
276
0
Silicon Valley
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
Commented out and script runs with no error
 

uplusd

macrumors 6502
Original poster
Apr 8, 2008
276
0
Silicon Valley
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.
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
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,842
7
USA
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.
 

-aggie-

macrumors P6
Jun 19, 2009
16,793
50
Where bunnies are welcome.
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.

I'm still on windows here. Did you change it to my post above.
Replacing url with home page.
 

uplusd

macrumors 6502
Original poster
Apr 8, 2008
276
0
Silicon Valley
I'm still on windows here. Did you change it to my post above.
Replacing url with home page.
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
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,842
7
USA
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 a 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
 

-aggie-

macrumors P6
Jun 19, 2009
16,793
50
Where bunnies are welcome.
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.
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.
 

-aggie-

macrumors P6
Jun 19, 2009
16,793
50
Where bunnies are welcome.
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.
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?
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,842
7
USA
Off topic, but do you know where the data for Address Book is on OSX?
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.
 

-aggie-

macrumors P6
Jun 19, 2009
16,793
50
Where bunnies are welcome.
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.
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.
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,842
7
USA
I wanted to know where it was so I could make a copy before messing with it.
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.