Blog
Blog
I spent hours today learning AppleScript. Of course I spent more time trying to write the script than it would have probably taken to just manually fix my Address Book, but what’s the fun in that?
It’s an AppleScript that searches for all your contacts phone numbers, and if there’s a leading + symbol (for dialing on my mobile phone), it replaces it with 00, which will work with landlines.
I did this for support of the MaxRoam SIM, which promises cheaper international roaming. All this to save a few euros for work.
Script can be changeplus.scpt.
Or here’s the code in it:
-- Change Plus in Address Book Phone Numbers version 1.0
-- June 24, 2008 - Somewhere in the air between Amsterdam and Dubai
-- By Pete Crocker <pete@petecrocker.com>
-- CC BY-NC-SA Some Rights Reserved
-- A boolean to determine if the script should actually apply changes
-- to the Address Book database. If "true" this will _not_ change any
-- data in the Address Book database. If "false" this script _will_
-- *overwrite* phone number information in the Address Book database.
property _isTesting : true
property _scriptName : "Change Plus to 00 in Address Book"
on run
tell application "Address Book"
set _people to get every person
repeat with indx1 from 1 to number of items in _people
set _person to item indx1 of _people
set _phoneList to every phone of _person
repeat with indx2 from 1 to number of items in _phoneList
set _oldPhone to value of item indx2 of _phoneList
if _oldPhone starts with "+" then
set _newPhone to my changePlus(_oldPhone)
if (_isTesting is false) then
set value of phone indx2 of _person to _newPhone as string
end if
end if
end repeat
end repeat
end tell
end run
on changePlus(_oldNumber)
-- Ugly but works!!!
set _newNumber to "00" & text 2 thru -1 of _oldNumber
return _newNumber
end changePlus
AppleScript Adventures - Change Characters
6/24/08