Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
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.

I was up late and didn't get anywhere either. I think the reason it is not changing/emptying the field is due to the fact that everything being acted upon are variables that take on the value of the stuff we're trying to change. So, when you set the "value of this_url" to "" it doesn't affect what is stored. Does that make sense?

Edit: This is strange. I finally get all the urls to go to "" but they're not changed in Address Book. Any ideas?

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 (value of this_url)
				--display dialog (value of this_url)
				--set (value of this_url) to ""
				set value of url of this_person to ""
				display dialog "got here"
				display dialog (value of this_url)
			end repeat
		end if
	end repeat
	display dialog output
end tell

I added this line: set value of url of this_person to ""

This seems to zero out the urls, but doesn't fix it in the actual address book.
 
I was up late and didn't get anywhere either. I think the reason it is not changing/emptying the field is due to the fact that everything being acted upon are variables that take on the value of the stuff we're trying to change. So, when you set the "value of this_url" to "" it doesn't affect what is stored. Does that make sense?

Edit: This is strange. I finally get all the urls to go to "" but they're not changed in Address Book. Any ideas?

I was coming to the same conclusion. I could "remove" things from AppleScripts perspective, as the URLs would be gone on a second run of the script, but Address Book wouldn't change at all, and restarting it would cause the script to start from scratch. I did find a script that removes emails of a certain label, and I modified it for URLs, but no go. Though that script didn't work on emails for me. I think maybe something changed in Snow Leopard that's causing issues with it.

@OP (uplusd), you can use the SQLite browser method I mentioned earlier to get rid of the URLs pretty easily. It's just weird the AppleScript stuff isn;t working.
 
I was coming to the same conclusion. I could "remove" things from AppleScripts perspective, as the URLs would be gone on a second run of the script, but Address Book wouldn't change at all, and restarting it would cause the script to start from scratch. I did find a script that removes emails of a certain label, and I modified it for URLs, but no go. Though that script didn't work on emails for me. I think maybe something changed in Snow Leopard that's causing issues with it.

@OP (uplusd), you can use the SQLite browser method I mentioned earlier to get rid of the URLs pretty easily. It's just weird the AppleScript stuff isn;t working.

I had already seen this AppleScript but passed it over. Anyway, I downloaded it just now, and after figuring out I had to have the contact in Address Book selected to use it and that I had to pick the name of the email label ("home" for my case), it said one email deleted. Of course, it wasn't deleted. What a pain. I'm clueless what to do.
 
I had already seen this AppleScript but passed it over. Anyway, I downloaded it just now, and after figuring out I had to have the contact in Address Book selected to use it and that I had to pick the name of the email label ("home" for my case), it said one email deleted. Of course, it wasn't deleted. What a pain. I'm clueless what to do.

That script doesn't tell Address Book to save after it finishes its modifications. See my earlier post. Directly above yours.
 
What OS version?

Where did you put the save? Post the code.

At what point did you get the error?

OS 10.6.2, the same as angelwatt, I would think.

Right before the end tell.

PHP:
tell application "Address Book"
	
	set emails_removed to 0
	repeat with this_person in (get selection)
		set emails_to_remove to {}
		repeat with this_email in every email of this_person
			--display dialog of this_email
			if the label of this_email is equal to the_label then
				set emails_to_remove to emails_to_remove & (id of this_email)
				--display dialog this_email
			end if
		end repeat
		repeat with email_id in emails_to_remove
			--display dialog (the email of this_person whose id is email_id) as string
			delete (the emails of this_person whose id is email_id)
			--display dialog (the emails of this_person whose id is email_id)
			set emails_removed to emails_removed + 1
		end repeat
	end repeat
	
	display dialog "Removed " & emails_removed & " email addresses."
	--display dialog emails_removed
	save
end tell

I originally had "display dialog "Removed " & emails_removed & " email addresses."" commented out. Once I took out the comments, now it works. Strange.

However I still get the error/warning, but it does remove the email address.

Here's the error:

PHP:
	save current application
		--> missing value
end tell
Result:
missing value
 
Well, OP, I finally got this to work. Here you go and use at your own risk. You should save the contents of the folder ~/Library/Application Support/Addressbook before using this. If something goes wrong, you can simply paste back the 5 files and everything will be back as it was.

Here are the 5 files:
AddressBook-v22.abcddb
Configuration.plist
Images
MailRecents-v4.abcdmr
Metadata

Here is the long awaited AppleScript:

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
				set value of url of this_person to ""
			end repeat
		end if
	end repeat
	display dialog output
	save
end tell

I know this was a double post. When the OP see this, I'll have it merged. Thanks to angelwatt and chown33.
 
FWIW, Address Book won't update until the script tells Address Book to save.

I knew it would be something simple like that. It always is with AppleScript. AppleScript solutions always look so simple they make you feel stupid. I had come across some scripts that mentioned doing a save, but couldn't find them when I wanted to. Thanks for the link.

Nice write-up Aggie.

As a note to those who run it: The lines dealing with the "output" variable are optional, but is handy to see what's getting deleted afterward the script is done. If you comment out the line setting the value to "" you can run the script in test-mode to make sure it's deleting the right things. If you're deleting a lot of urls, then the OK button on the dialog that displays the output will be off the screen. Simply hit your return key to close it.
 
Here is an updated version which only remove Facebook fb:// URLs and keep the others.

As usual :
- BACKUP BEFORE USING IT
- USE AT YOUR OWN RTISKS

Code:
--saves the text item delimiters:
set savedDelimiters to AppleScript's text item delimiters
try
	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 
					if (value of this_url as string) ≠ "" then
						set AppleScript's text item delimiters to {":"}
						set proto to first text item of (value of this_url as string)
						--now reset the text item delimiters:
						set AppleScript's text item delimiters to savedDelimiters
						if proto = "fb" then
							set output to output & (value of this_url as string) & return
							set value of url of this_person to ""
						end if
					end if
				end repeat
			end if
		end repeat
		display dialog output
		save
	end tell
on error m number n
	--also reset text item delimiters in case of an error:
	set AppleScript's text item delimiters to savedDelimiters
	--and resignal the error:
	error m number n
end try
 
C++ Alternative

I got fed up trying to do this with an AppleScript as well. Here's a C++ alternative.

Read code comment for the explanation.

Code:
/*

 This program will remove the fb://profile links from your 
 contact cards. I would suggest creating an addressbook archive 
 first before running this against your actual contacts. The easiest
 way to use this is to search your contact cards for "profile" select
 all and export as a single vCard. Then compile and run this program with
 that vCard as input and specify an output file, say fbRemoved.vcf

 I found that AddressBook behaves oddly when I try to do a mass import
 when selecting use new for all cards. To get around this I just deleted all 
 cards I had selected in the "profile" search then imported fbRemoved.vcf

 Written by: Alexander Millar
 Date: 30 Feb 2010

*/

#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <fstream>
#include <string>

using namespace std;

bool contains_fb_link(string str) {
  size_t found;
  found = str.find("fb\\://profile/");
  if(found!=string::npos) 
  { 
    return true;
  }
  return false;
}

int main( int argc, char *argv[] ) {
  istream *infile;
  ostream *outfile = &cout;
  string str;

  switch ( argc ) {
  case 3:
    outfile = new ofstream( argv[2] );
    if ( outfile->fail() ) 
    {
      cerr << "Error! Could not open output file \"" << argv[2] << "\"" << endl;
      exit(-1);
    }
  case 2:
    infile = new ifstream( argv[1] );
    if ( infile->fail() ) 
    {
      cerr << "Error! Could not open input filee\"" << argv[1] << "\"" << endl;
      exit(-1);
    }
    break;
  default:
    cerr << "Usage: " << argv[0] << " input-file [output-file]" << endl;
  }


  for ( ;; )
  {
    getline(*infile,str);
    if( infile->eof() ) break ;		

    if(contains_fb_link(str))
    {
      getline(*infile,str);
      if( infile->eof() ) break ;
    }
    else
    {
      *outfile << str << endl;
    }   
  }
}
 
Well, OP, I finally got this to work. Here you go and use at your own risk. You should save the contents of the folder ~/Library/Application Support/Addressbook before using this. If something goes wrong, you can simply paste back the 5 files and everything will be back as it was.

Here are the 5 files:
AddressBook-v22.abcddb
Configuration.plist
Images
MailRecents-v4.abcdmr
Metadata

Here is the long awaited AppleScript:

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
				set value of url of this_person to ""
			end repeat
		end if
	end repeat
	display dialog output
	save
end tell

I know this was a double post. When the OP see this, I'll have it merged. Thanks to angelwatt and chown33.

This worked flawlessly for me!!!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.