Home Page | Project Page at SourceForge
This file is a tutorial that demonstrates the [addressbook] command defined by the Tcladdressbook extension for Tcl. It documents version 1.2.2. All the Tcl instructions in the sections below are very short one-line commands which you can try in any Tcl shell, like tclsh for instance.
For a detailed and complete description of the syntax of each subcommand, refer to the help file. The home page for Tcladdressbook is on the SourceForge site.
package require addressbook
addressbook groupsList all the groups (only ID)
addressbook groups -idsList the subgroups of a specific group (ID and name)
set groupid [lindex [addressbook groups -ids] 0] addressbook groups -ingroup $groupidList the subgroups of a specific group (only ID)
addressbook groups -ids -ingroup $groupid
addressbook personsList all the persons records (only ID)
addressbook persons -ids
addressbook count -groups addressbook count -persons addressbook count -persons -ingroup [lindex [addressbook groups -ids] 0]
set myrecord [addressbook getme]The value of myrecord is a keyed list. One can use the usual Tcl list commands to parse this value or special commands defined in the TclX extension (see section Using keyed lists below).
The getme command can also be used with an -id option. In that case the unique ID of the "Me" record is returned:
set myID [addressbook getme -id]
set theid [lindex [addressbook persons -ids] 2] addressbook setme $theid addressbook save
set theid [lindex [addressbook persons -ids] 0]Store the info about this record in the variable person. The returned value has the same keyed list format as with the [getme] subcommand.
set person [addressbook record $theid]
Similarly with a group: store the ID of the first group in the variable theid
set theid [lindex [addressbook groups -ids] 0]Store the info about this group in the variable grp
set grp [addressbook record $theid]
addressbook type $theid
addressbook create group WorkingCommittee addressbook create person BeethovenOne can make them subgroups or members of an already existing group using the -ingroup option:
set grpid [lindex [addressbook groups -ids] 0] set subgrpid [addressbook create group Composers -ingroup $grpid] addressbook create person Beethoven -ingroup $subgrpid
addressbook delete $theidCheck that there were changes (1 if yes, 0 if no)
addressbook changedSave the changes to make them permanent
addressbook save
set groupid [lindex [addressbook groups -ids] 0] set theid [lindex [addressbook persons -ids] 0] addressbook add $groupid $theidOne can add several items at a time with this command:
addressbook add $groupid $theid1 $theid2 $theid3
set groupid [lindex [addressbook groups -ids] 0] set theid [lindex [addressbook persons -ids] 0] addressbook remove $groupid $theidOne can remove several items at a time with this command:
addressbook remove $groupid $theid1 $theid2 $theid3
set theid [lindex [addressbook persons -ids] 0] addressbook parents $theidList the parents of a person record (only ID)
addressbook parents -ids $theid
One can also find the parents of a group using this command.
set theid [addressbook getme -id] addressbook label $theid Phone 0The returned string could be Home for instance. Let's change it to Personal:
addressbook label $theid Phone 0 Personal addressbook save
set theid [lindex [addressbook persons -ids] 0] addressbook set $theid First addressbook set $theid ABDate addressbook set $theid AddressTo change the first name of the first record:
addressbook set $theid First Georgios addressbook changed addressbook saveNote that the addressbook save command must be invoked to make the changes permanent.
When setting the value of a field it is important that the new value be formatted correctly with respect to the type of the property, as explained in the help file. Here are a few examples corresponding to various property types:
addressbook set $theid Email {{Work BWV@harpsichord.com} {Concerts opus@sonatas.org}}
addressbook set $theid Birthday [clock scan "1 Apr 1985"]
addressbook set $theid ABDate [list [list "birthday Franny" 621597600] [list "birthday Zooey" 816692400]]
addressbook set $theid Address [list [list Home [list {CountryCode fr} {City Paris} {Country France} {ZIP 75001} {Street "1, avenue de l'Opéra"}]]]
See also the examples in the section Using keyed lists below: the [keylget] and [keylset] commands defined in the TclX extension can be very useful to format multivalues correctly.
addressbook search Last == "Bach" addressbook search -persons -ids -nocase Last > "Ba" addressbook search -persons Modification >= 1070199949 addressbook search -persons Modification < 1070199949
When searching on a particular property, it is important that the searched value be formatted correctly with respect to the type of the property, as explained in the help file. Specify an empty label or an empty key to search on all possible labels or keys respectively. Here are a few examples corresponding to various property types:
addressbook search -persons Phone == {Work "01 02 03 04 05"}
addressbook search -persons Phone > {"" "01 02 03 04 05"}
addressbook search -persons -nocase Address == {Home {ZIP 98765}} addressbook search -persons -nocase Address > {Home {ZIP 98}}
addressbook search -persons -nocase Address > {"" {City Paris}}
addressbook search -persons -nocase Address > {home {"" abc}}
addressbook search -persons -nocase Address > {"" {"" abc}}
addressbook search -persons Address ^= {Home {City "Par"}}
addressbook search -persons Email =$ {Home ".com"}
addressbook search -persons Email !> {Home "xyz"}
addressbook property names -groups addressbook property names -persons
addressbook property type -groups UID addressbook property type -persons AddressFor the two examples above, the result is respectively String and MultiDictionary.
addressbook property add -persons Instrument String
Add a new group's property called Meeting with type Date
addressbook property add -groups Meeting Date
set theid [addressbook getme -id] addressbook set $theid MaidenName Violet addressbook save addressbook property remove $theid MaidenName
Remove the properties created above:
addressbook property remove -persons Instrument addressbook property remove -groups Meeting
Suppose theid is the record ID of a person in the group groupid:
set groupid [lindex [addressbook groups -ids] 0] set theid [lindex [addressbook persons -ids -ingroup $groupid] 0]
Count the identifiers of the Phone property:
addressbook identifier count $theid Phone
Get some identifiers by index (suppose here that there are at least two of them). Indices start at 0:
set ident1 [addressbook identifier get $theid Phone 0] set ident2 [addressbook identifier get $theid Phone 1]
Get the primary identifier (the one which is chosen by default if none has been specified otherwise):
addressbook identifier primary $theid Phone
Get the current distribution identifier:
addressbook identifier set $groupid $theid Phone
Set the distribution identifier to ident2:
addressbook identifier set $groupid $theid Phone $ident2
The reverse operation of the addressbook identifier get command is the addressbook identifier index command which returns the index corresponding to a given identifier. For instance, the following instruction will return the index 1:
addressbook identifier index $theid Phone $ident2
set theid [lindex [addressbook persons -ids] 0] set vcardData [addressbook export $theid]The data returned is binary. You can store it in a file for instance.
set fname [file join /Users bernardo someVcard.vcf] set fid [open $fname r] set vcard [read $fid] close $fid addressbook import $vcard
set theid [lindex [addressbook persons -ids] 0] set img [addressbook image $theid]The data returned is binary. You can store it in a file for instance. An error is raised if there is no custom image for this record.
package require Tclx keylkeys myrecord keylget myrecord Email.work keylget myrecord Address.home.ZIP clock format [keylget myrecord Birthday]Similarly, with a group, one can invoke:
set theid [lindex [addressbook groups -ids] 0] set grp [addressbook record $theid] keylkeys grp keylget grp GroupName clock format [keylget grp Modification]
To set a particular value, use the keylset command. For instance:
set personID [addressbook create person someName] keylset homeAddr City Paris Zip 75000 CountryCode fr set homeDict [list Home $homeAddr] addressbook set $personID Address [list $homeDict] set homeEmail "someName@home.org" set workEmail "someName@work.org" keylset emailsList Home $homeEmail Work $workEmail addressbook set $personID Email $emailsList
Last updated 2009-03-13 10:16:57