reoving + signs from phone numbers in address book

I’m try to write a script to remove all + signs from all phone numbers in Address Book.

the following throws up an error



tell application "Address Book"
repeat with Acontact in people
repeat with APhone in phones of Acontact
set current_phone to value of APhone

set value of APhone to do shell script "echo " & quoted form of current_phone & " | sed -e 's/+//g'"
end repeat
end repeat
end tell



The error it returns is that variable current_phone is not defined. could someone explain what’s wrong here?

Although the script you provided doesn’t really need to set current_phone, I believe you want:


set current_phone to APhone

no, that doesn’t work at all. you need to get value of Aphone to get an actual phone number.

However, You are right and current_phone is not needed. If I shorten it as follows


tell application "Address Book"
	repeat with Acontact in people
		repeat with APhone in phones of Acontact
			
			set value of APhone to do shell script "echo " & quoted form of (value of APhone as text) & " | sed -e 's/+//g'"
			
		end repeat
	end repeat
end tell


I get the following error:

can’t set item 2 of every phone of item 14 of every person to “”

Person 14 is the first AB entry with multiple phone numbers each having a + inside.

I’m not sure what’s going on then. This works for me:

tell application "Address Book"
	repeat with Acontact in people
		repeat with APhone in phones of Acontact
			set current_phone to value of APhone
			display dialog current_phone as text
		end repeat
	end repeat
end tell

:confused:

Hmm…
This also works:

tell application "Address Book"
	set mylist to every person in group "Sample Group"
	repeat with Acontact in mylist
		repeat with APhone in phones of Acontact
			set current_phone to value of APhone
			set value of APhone to do shell script "echo " & quoted form of current_phone & " | sed -e 's/+//g'"
		end repeat
	end repeat
end tell

I only have two people in my “Sample Group”, but it works!

for me it chokes on entries with multiple phone numbers (see my edit above). can you try that please?

Works for me. What version of the OS & Applescript are you using? I’m using:
10.4.11
AppleScript 1.10.7 Version 2.1.1 (81)

OS X 10.5.4

Apple Script 2.0.1

Do you really think the problem is with Apple script?!

It seems like it. File a bug report.

I’m on 10.5.4 also and this works for me. So my guess would be there’s something wrong with the shell command… which you can replace that with the simple if statement I use.

set thephones to {}
tell application "Address Book"
	repeat with Acontact in people
		repeat with APhone in phones of Acontact
			set thisNum to value of APhone
			if first item of thisNum is "+" then set thisNum to text 2 thru -1 of thisNum
			set end of thephones to thisNum
		end repeat
	end repeat
end tell
thephones