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?
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
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!
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