# File: "PhoneBook.tcl"
#                        Created: 2004-01-05 11:54:31
#              Last modification: 2004-01-23 08:58:13
# Author: Bernard Desgraupes
# e-mail: <bdesgraupes@easyconnect.fr>
# www: <http://webperso.easyconnect.fr/bdesgraupes/>
# Description: this simple script reads all the records from the Address Book
# and builds a phones list.  Each line of the output file contains the last
# name, the first name and the corresponding phone number(s).  The fields are
# tab separated.
# 
# This script has been placed in the public domain.

package require addressbook

set fid [open ABPhones.txt w+]
fconfigure $fid -encoding macRoman

foreach rid [addressbook persons -ids] {
    set line ""
    if {![catch {addressbook set $rid Last} res]} {
	append line $res
    } 
    append line "\t"
    if {![catch {addressbook set $rid First} res]} {
	append line $res
    } 
    if {![catch {addressbook set $rid Phone} res]} {
	foreach ph $res {append line "\t[lindex $ph 1]"}
    } 
    puts $fid $line
} 

close $fid