Benches Uncategorized

5

removing +s from phone numbers

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

Hi folks,
I was trying to write a script to remove + signs from any phone numbers that contain them.

the following script throws up an error for some reason.

<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #ADD8E6;
overflow: auto;"
title="this text can be pasted into the Script Editor">
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
</pre>

what's wrong here?

5 replies

Sign in or join Beachball Help to reply.

  1. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hi V.K.

    no error here, works a treat.

    Budgie

  2. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    well, for me it chokes up on the first contact with several phone numbers all containing + signs. It fixes the first phone number but errors out on the second one. the error message is: current_phone not defined

    Message was edited by: V.K.

  3. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I origionaly tested using only one phone number in x amount of contacts, just re-tested using multiple phone numbers in multiple contacts, still runs sweet here.

    Budgie

  4. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Try:

    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #FFDDFF;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    tell application "Address Book"
    repeat with Acontact in people
    repeat with APhone in (get 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</pre>

    Check the AppleScript Language Guide Commands Reference for get, specifically the part about Object Specifiers toward the end.

  5. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    brilliant!
    Thanks a lot!