Any script to delete specific website mentioned in "IM" fields in All?

it seems that you can’t delete social profiles with AppleScript in Lion.
I tried (hopefully) every possible syntax.

Last try was


tell application "Address Book"
	repeat with p in every person
		repeat with i from 1 to (count social profiles of p)
			if url of social profile i of p contains "https://www.facebook.com/profile.php" then
				set profilID to id of social profile i of p
				delete (1st social profile of p whose id is profilID)
			end if
		end repeat
	end repeat
end tell


failed too

Anyone else with a solution ?

Hello.

if you google for docs on tools for Address book at Apple Developer, tjem I guess something usable will show up, as the addressbook is used on their servers, as a centralized solution for contact managment, for their customers. So I guess, or think it is an admin tool for addressbook, and that may help you. But I guarantee zip!

Cheers!

I did some search and nothing came up. Did you find anything ? if yes, can you post it here please ? it would really appreciated :slight_smile:

Indeed it’s possible to manage all properties and elements with Objective-C but as the sample projects are created with pre-10.7 environment, none of the sample code provides access to the social profiles element.

As a workaround this script adds the people with a Facebook profile to a new group “facebook” in Address Book,
then you could delete the profiles manually


tell application "Address Book"
	set filteredPeople to every person whose service name of social profiles contains "facebook.com"
	make new group with properties {name:"facebook"}
	repeat with aPerson in filteredPeople
		add aPerson to group "facebook"
	end repeat
	save
end tell

Thanks StefanK for your help the script

Does that mean that all cards with facebook.com are being moved to the “Facebook” group and I will have to manually bring them back to their original groups ?

The original groups aren’t touched. A card can be assigned to more than one group

It says it’s “missing value”

I don’t use FaceBook at all, but I tested it successfully on Lion with a few test cards.
Maybe the real service name doesn’t match “facebook.com

Here’s a screenshot of an Address Book card I have:

I have to delete both “all” Facebook and Twitter social profiles accounts on all cards because they’ve been doubled

The question is how the service name appears in the appropriate AppleScript property

Sorry but I didn’t get that. What do you mean ?

this line


 set filteredPeople to every person whose service name of social profiles contains "facebook.com"

expects “facebook.com” as the service name of a Facebook account, maybe the real name is different

I dont know if this helps or not. The values you’re looking at are in the class “ABMultiValue”. They won’t be referenced by a single Applescript descriptor. You’ll need to get the group (array) of items in the class ABMultiValue, then iterate through each item for each person record, looking for the value of the item. Then use “ removeValueAndLabelAtIndex: This might need to occur in ObjC.
StefanK, I think you are on the right track. Check out the XCode docs for ABMultiValue Class Reference

I know how to do this in ObjC. But it’s beyond the level of pure AppleScript

Thanks StefanK & SuperMacGuy

What would be the full recommended script then ?

Anyone else with AppleScript knowledge using Lion 10.7 can get this done ? PLEASE :slight_smile:

The possible ObjC solution isn’t AppleScript compatible

Pure AppleScript can’t do it, sorry

Someone said suggested the following in another forum:

tell application “Address Book”
repeat with thisPerson in people
set FBSocialProfiles to (every social profile of thisPerson whose service name contains “Facebook”)
if FBSocialProfiles ≠{} then
– has a facebook profile
add thisPerson to group “facebook”
end if
end repeat

save
end tell

On second thought, this might be somewhat faster. or it might not be. 

tell application “Address Book”
set FBSocialProfiles to (every person whose social profiles’s service name contains “Facebook”)
repeat with thisPerson in FBSocialProfile
add FBSocialProfiles to group “facebook”
end repeat
end tell

Any comments ?

Finally got this to work through some trial and error - not perfect by any stretch, but it does work. You can replace “Facebook” with the name of any other social network and it will remove those too. Apparently if you delete the url and user name, it will also nuke the whole social profile. Enjoy!


tell application "Address Book"
	repeat with thisPerson in people
		set SocialProfileList to (every social profile of thisPerson whose service name contains "Facebook")
		if SocialProfileList ≠ {} then
			-- has a social profile
			delete (url of every social profile of thisPerson)
			delete (user name of social profile of thisPerson)
		end if
	end repeat
	save
end tell