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:


  1. -- Change Plus in Address Book Phone Numbers  version 1.0

  2. -- June 24, 2008 - Somewhere in the air between Amsterdam and Dubai

  3. -- By Pete Crocker <pete@petecrocker.com>

  4. -- CC BY-NC-SA Some Rights Reserved

  5. -- http://creativecommons.org/licenses/by-nc-sa/3.0/


  6. -- A boolean to determine if the script should actually apply changes

  7. -- to the Address Book database.  If "true" this will _not_ change any

  8. -- data in the Address Book database. If "false" this script _will_ 

  9. -- *overwrite* phone number information in the Address Book database.


  10. property _isTesting : true


  11. property _scriptName : "Change Plus to 00 in Address Book"


  12. on run

  13. tell application "Address Book"

  14. set _people to get every person


  15. repeat with indx1 from 1 to number of items in _people

  16. set _person to item indx1 of _people

  17. set _phoneList to every phone of _person


  18. repeat with indx2 from 1 to number of items in _phoneList

  19. set _oldPhone to value of item indx2 of _phoneList

  20. if _oldPhone starts with "+" then

  21. set _newPhone to my changePlus(_oldPhone)

  22. if (_isTesting is false) then

  23. set value of phone indx2 of _person to _newPhone as string

  24. end if

  25. end if

  26. end repeat

  27. end repeat

  28. end tell

  29. end run


  30. on changePlus(_oldNumber)

  31. -- Ugly but works!!!

  32. set _newNumber to "00" & text 2 thru -1 of _oldNumber

  33. return _newNumber

  34. end changePlus


 

AppleScript Adventures - Change Characters

6/24/08

< Previous

Next >