Egypt Mobile numbers code changes in Mac Address Book ????? ????? ???????? ???? ??? ?????
on November 16th, 2011 at 5:15 PMHere is a an Apple Script to modify your address book entries to adjust the new mobile codes in Egypt (Without 150, 151, 152 codes).
Just open AppleScript, paste the script below and run it, it will print a list of numbers to be modified for checking (old number : new number pair). To modify the Address Book, remove comment on line marked (R) and comment the two lines marked (C) and run. Enjoy. [Note: this is a modified version of the script listed here https://discussions.apple.com/thread/1696591?start=0&tstart=0]
You can get a text file with the script here
–Script Begin
tell application “Address Book”
set nm to {} as list
repeat with p in (get people)
repeat with n in (get p’s phones)
set m to my edit1(get n’s value)
if n’s value ? m then
copy (n’s value & ” : ” & m) to end of nm — (C)Comment to modify the address book
–set n’s value to m –(R)Uncomment to modify the address book
end if
end repeat
end repeat
return nm — (C)Comment to modify the address book
end tell
on edit1(n)
set m to prefix(n, 100, 10)
if m ? n then return m
set m to prefix(n, 106, 16)
if m ? n then return m
set m to prefix(n, 109, 19)
if m ? n then return m
set m to prefix(n, 122, 12)
if m ? n then return m
set m to prefix(n, 128, 18)
if m ? n then return m
set m to prefix(n, 127, 17)
if m ? n then return m
set m to prefix(n, 111, 11)
if m ? n then return m
set m to prefix(n, 114, 14)
return m
end edit1
on prefix(n, p, rr)
(*
string or number n : source number
string or number p : prefix number to add
list rr : string of target number
return string : modified number (country code part is kept unchanged)
*)
script o
property _onlyWithCountryCode : false — true for processing only numbers with country code; false otherwise
property countrycodepart : {“+20″, “0020″, “0″} — list of country code parts
– (1) decompose number into country code part (=n1) and the domestic part (=n2)
set n to n as string — for safety
set nlen to count n
set n1 to “”
repeat with q in my countrycodepart
set q to q’s contents
if n starts with q then
repeat with i from (count q) + 1 to nlen
if n’s character i is not in {space, tab} then exit repeat
end repeat
set n1 to n’s text 1 thru (i – 1)
set n2 to n’s text i thru -1
exit repeat
end if
end repeat
if n1 = “” then
if _onlyWithCountryCode then return n — leave the number without country code
set n2 to n
end if
– (2) extract digits for n2 (=n2d) and check its length
set n2d to “”
repeat with x in n2
if x is in “0123456789″ then set n2d to n2d & x
end repeat
if (count n2d) is not 9 then return n — leave the number whose domestic part is not of 9 digits
– (3) modify the domestic part according to kk and re-compose the number
set kk to rr as string
set n3 to n2′s text ((count kk) + 1) thru -1
if n2d starts with kk then return n1 & p & n3
return n
end script
considering case
tell o to run
end considering
end prefix
–Script End