Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

uplusd

macrumors 6502
Original poster
Apr 8, 2008
279
4
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!
 
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. :)
 
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
 
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
 
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
 
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.

455d4c4026d8847474bc7710eda94ef3.png


looks like its 'homepage' hehe
 
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
 
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.
 
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.
 
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
 
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
 
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.
 
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.

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.
 

Attachments

  • Screen shot 2010-03-05 at 8.07.49 PM.PNG
    Screen shot 2010-03-05 at 8.07.49 PM.PNG
    103.6 KB · Views: 301
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?
 
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.
 
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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.