tcladdressbook(1)

This page documents version 1.2.2 of the Tcladdressbook extension.

NAME

addressbook - manipulate the Macintosh OS X Address Book database

SYNOPSIS

package require addressbook

 addressbook subcommand ? arg arg...?

INTRODUCTION

The argument subcommand indicates the operation to perform. Any unique abbreviation for each subcommand is acceptable. The valid subcommands are explained in the next sections.

SUBCOMMANDS

  addressbook add groupID recordID ?recordID ...?

This command lets you add one or more already existing items (persons or groups) designated by their unique ID recordID to the group with ID groupID.

  addressbook changed

This command returns 1 if there has been changes made to the database, 0 otherwise. Changes are made in memory with commands such as addressbook set, addressbook create, addressbook delete. To make these changes permanent, one must call the addressbook save command.

  addressbook count (-groups | -persons) ?-ingroup groupID?

This command returns the count of existing groups or persons in the database. One can specify a particular group with the -ingroup option to count only the subgroups or members in this group.

  addressbook create (group | person) name ?-ingroup groupID?

This command lets you create a new group or a new person record. The name argument is the name to give to the new group or the last name of the person for which a new record is created. With the -ingroup option one can make the newly created record a subgroup or a member of the particular group with unique ID groupID. If no error occurs, the command returns the unique ID of the created record.

  addressbook delete recordID

This command removes the record with unique ID recordID from the database. Note that any changes made to the database won't be definitive until you invoke the addressbook save command.

 In version 1.0 of the extension, this command used to accept an option called -fromgroup in order to remove the record from a particular subgroup. This is achieved now by the addressbook remove command.

  addressbook export personID

This command lets you export the record with unique ID personID as a VCard. The result should be considered as binary data since it can contain an image associated to the record.

  addressbook getme ? -id?

This command returns the ID or the data corresponding to the logged-in user ("Me", aka personal record). If the -id option is specified, it returns the unique ID of the logged-in user. Otherwise the returned value takes the form of a keyed list: see the addressbook record command for a description of this format. Keyed lists can be easily manipulated with the keylget and keylset commands defined in the TclX extension. If no record is declared as the personal record, the command raises an error.

  addressbook groups ?-ids? ?-ingroup groupID?

This command returns a list of all the existing group records: if no option is specified, it is a list whose elements are sublists made of two elements. The first element is the unique ID associated with the group and the second is its name. If the -ids argument is specified, the returned list will contain only the unique IDs of the groups. If the -ingroup option is specified, only the subgroups contained in the group with ID groupID will be returned.

  addressbook identifier count personID propName

This command returns the number of items in a multi-value list property (such as Phone, Email, Address, MSNInstant etc.).

  addressbook identifier get personID propName index

This command gets the unique identifier of an item in a multi-value list property (such as Phone, Email, Address). It returns the identifier of the item at index index in the multi-value list of property propName for the record corresponding to personID. One can get the count of identifiers using the addressbook identifier count command. Identifiers are used by the addressbook identifier set command. See the section Distribution lists and identifiers <#dist> below for explanations about identifiers.

  addressbook identifier index personID propName ident

This command returns the index in a multi-value list corresponding to the identifier given in the ident argument. If ident is not a valid identifier, the command raises an error. The valid identifers are the values obtained by the addressbook identifier get command.

  addressbook identifier primary personID propName ? ident?

This command lets you get or set the primary identifier of property propName in the record personID. This is the identifier which will be used by default if no distribution identifier has been specified using the addressbook identifier set command. Property propName must be a multi-value list property (such as Phone, Email, Address).

 Used without the ident argument, the command will return the primary identifier concerning property propName for the person personID.

 If the ident argument is specified, the command will set the primary value to be the value for the given identifier ident. This value must be a valid identifier used by the multi-value list: one can get the identifiers of any element of a multi-value list using the addressbook identifier get command.

  addressbook identifier set groupID personID propName ? ident?

This command lets you get or set the distribution identifier for a multi-value list property of a person in a group. See the section Distribution lists and identifiers <#dist> below for explanations about identifiers.

 Used without the ident argument, the command will return the distribution identifier for the person personID belonging to the group groupID concerning property propName if it was set, otherwise the property's primary identifier. Property propName must be a multi-value list property (such as Phone, Email, Address).

 If the ident argument is specified, this will assign a specific distribution identifier for the person's multi-value list property so that the group can be used as a distribution list (a mailing list for instance, in the case of an email property). This value must be a valid identifier used by the multi-value list: one can get the identifiers of any element of a multi-value list using the addressbook identifier get command.

  addressbook image personID ? imageData?

If no imageData argument is specified, this command returns the custom image associated with the record corresponding to the unique ID personID. The returned bytes are binary data. If no image exists, it raises an error. If an imageData argument is specified, it should contain valid binary data defining an image which will be associated to the record with unique ID personID.

  addressbook import vCardData

This command imports data in VCard format. The data specified by the vCardData argument must be valid data in VCard format: a new person's record is created in the database corresponding to the information contained in the VCard. The VCard data must correspond to a single person: the command can't import multiple VCards, only one at a time. The return value, in case of success, it the record ID of the newly created person's record. Note that the data can be binary if the VCard contains an image. Starting from version 1.1.1 of the extension, the image is also imported by the command as a custom icon for the record.

  addressbook label recordID propName index ? value?

This command lets you get or set the label of a value in a multi-value property for a particular record. If the property propName is not a multivalue property, the command raises an error.

 Used without the value argument, the command will return the current label at index index in property propName for the record specified by recordID. To determine the index range, one can use the addressbook identifier count command.

 If the value argument is specified, the command will set the label at index index to this value.

  addressbook parents ?-ids? recordID

This command returns a list of all the groups the record with unique ID recordID belongs to. The elements of this list are sublists made of one or two items: the unique ID and, possibly, the name of the record if this field exists. If the -ids option is specified, only IDs are returned.

  addressbook persons ?-ids? ?-ingroup groupID?

This command returns a list of all the existing person records: if no option is specified, it is a list whose elements are sublists made of one or two items: the unique ID and, possibly, the name of the record if this field exists. If the -ids argument is specified, the returned list will contain only the unique IDs. If the -ingroup option is specified, only the members belonging to the group with ID groupID will be returned.

  addressbook property names (-groups | -persons)

This command returns a list of all the properties defined in the database for group or person records. New properties can be created or removed with the addressbook property add and addressbook property remove commands.

  addressbook property type (-groups | -persons) propName

This command returns the type of the property specified by the propName argument. The returned type is one of the values listed with the addressbook property add command below or Unknown.

  addressbook property add (-groups | -persons) propName propType

This command lets you add a new property to the database, either for person or for group records. The name of the new property is specified by the propName argument: it must be unique. One can get the list of all the existing properties with the addressbook property names command. The type of the property is specified by the propType argument. This argument can have one of the following values: Array, Data, Date, Dictionary, Integer, Real, String, MultiArray, MultiData, MultiDate, MultiDictionary, MultiInteger, MultiReal, MultiString.

  addressbook property remove (-groups | -persons | recordID) propName

This command lets you remove a property from the database, either for person or group records, or for a particular record specified by the recordID argument. The name of the property is specified in the propName argument. If the third argument is either -groups or -persons, the command should remove the given property from all the records of this type in the Address Book database. Otherwise the third argument should be the record ID of a particular person or group: the property is removed for this record only. The command returns 1 in case of success.

 One can get the list of all the existing properties with the addressbook property names command.

 WARNING: This command is currently only working with a recordID argument. It does not work with the -groups or -persons options and always returns the value 0 in that case, because the function ABRemoveProperties is not fully implemented in the AddressBook framework. Invoking it leaves the following message in the console:

     "Removal of custom properties is not yet implemented"

  addressbook record recordID

This command returns all the data available in the database concerning the record with unique ID recordID. The returned value takes the form of a keyed list.

 The format used for a particular property's value depends on the type of the property (string, integer, date, multivalue etc.). Some properties have a multiple type: MultiString for fields like Email, Phone etc., MultiDate for fields like ABDate, MultiDictionary for the Address field. In case of a multivalue, the returned value is a keyed list itself. Each element of the list corresponds to a single property. For instance:

    *   the elements of a MultiString or MultiDate value list are two-elements sublists: the first element is the label of the corresponding property (like Home, Work etc.) and the second is the value itself.

    *   the elements of a MultiDictionary value list are lists themselves, representing a Label/Dictionary pair (dictionary in the AddressBook sense, not a Tcl dictionary as defined in version 8.5 of Tcl). Each element of this list has two elements: the first one is the label describing the address (like Home, Work etc.) and the second one is a list representing the dictionary. The lists representing dictionaries contain two-elements sublists: the first item is the key in the dictionary and the second one is the value associated with this key. For instance a person could have two addresses: each address will be returned as a Label/Dictionary pair; the elements of the dictionary are pairs like {City Paris} or {CountryCode fr}.

 Dates are returned as values suitable for use with the clock format Tcl command. It is the number of seconds relative to "Thu Jan 01 00:00:00 GMT 1970".

 Note that keyed lists can be easily manipulated using the keylget and keylset commands defined in the TclX extension.

  addressbook remove groupID recordID ?recordID ...?

This command lets you remove one or more already existing items (persons or groups) designated by their unique ID recordID from the group with ID groupID.

  addressbook save

This command lets you save the changes made in the database. Commands such as addressbook set, addressbook create or addressbook delete modify the data in memory: to make the changes definitive in the database, one must call explicitely the addressbook save command. To check whether there has been changes in the database, use the addressbook changed command.

  addressbook search ?(-groups | -persons)? ?-ids? ?-nocase? property op value

This command returns all the records corresponding to the criterion described by the last three arguments:

    *   property is the name of the property you are searching on.

    *   op is an operator specifying the type of comparison. It can be one of the following symbols:

            ==, !=, <, <=, >, >=, !<, !>, ^=, =$

    which may have different interpretations depending on whether the value is numeric or is a string.

        *   For a numeric value, they correspond respectively to:

                ==	Equal
                !=	Not Equal
                <	Less Than
                <=	Less Than or Equal
                !>	Less Than or Equal
                >	Greater Than
                >=	Greater Than or Equal
                !<	Greater Than or Equal

        The ^= and =$ operators are not applicable for numeric values and will raise an error.

        *   For a string value, they correspond respectively to:

                ==	Equal
                !=	Not Equal
                >	Contains Substring
                !>	Does Not Contain Substring
                ^=	Prefix Match
                =$	Suffix Match

        The ^= and =$ operators match respectively at the beginning or at the end of the string value (they are inspired by the ^ and $ symbols used in regular expressions). The <, <= and !< operators are not applicable for string values and will raise an error. The > and >= operators are equivalent.

    *   the argument value is the value you are searching for. In the case of a simple property, value will be a simple string. In the case of a MultiString, MultiInteger or MultiDate property, value will be a two-elements list representing a label/value pair. In the case of a MultiDictionary property, value will be a two-elements list representing a label/dictionary pair, the dictionary itself being a two-elements list representing a single key/value pair. For instance:

            {Phone "01 02 03 04 05"}
            {Home {City Paris}}

     One can specify an empty string for the label in order to perform the search over all the possible labels. One can also specify an empty string for the key in order to perform the search over all the possible keys in a dictionary.

 The -groups or -persons options let you specify the kind of records you want to search. If it is not specified, the default is -persons. If the -ids option is specified, only IDs of the matching records are returned, rather than pairs made of the ID and the name. The -nocase argument concerns string comparisons and requires that no distinction be made between uppercase and lowercase letters.

 To get a list of all possible properties, use the addressbook property names command. To know the type of a particular property, use the addressbook property type command.

  addressbook set recordID propertyName ? value?

This command lets you get or set the value of a particular property for the record with unique ID recordID. If the value argument is not specified, it returns the current value of the property specified in the propertyName argument. If value is specified, the property propertyName will be set to this value. See the addressbook record command for a description of the format used for the various kinds of properties.

  addressbook setme recordID

This command sets the record that represents the logged-in user.

  addressbook type recordID

This command returns the type ( ABPerson or ABGroup) of the record with unique ID recordID.

DISTRIBUTION LISTS AND IDENTIFIERS

Identifiers are necessary when one wants to use a group as a distribution list, that is send something to all the members of the group. The members can be addressed by Address, Phone, Email etc. For instance, a group could be used as a mailing list. The Address, Phone, Email properties are multi-value list properties: since a person can have several e-mail addresses, one must specify which one is to be used in the distribution list. Labels (such as Home, Work etc.) are not sufficient to specify precisely an e-mail because they are not unique: one can have several e-mails with the label Work. Here the identifiers come in: each value of a multi-value list property has an identifier. One of them can be designated as the distribution identifier. The AddressBook database also has a notion of a primary identifier: it is the identifier which will be used by default by the distribution list if no distribution identifier as been specified.

INSTALLATION

The extension is made of two files: the dynamic library (called libTcladdressbook1.1.dylib in version 1.1) and a file pkgIndex.tcl necessary for Tcl to be able to locate the extension upon request. Both files are contained in a directory called TclAddressBook1.1, in version 1.1. This directory should be installed on your system in /Library/Tcl or in ~/Library/Tcl or, more generally, in any directory contained in your auto_path Tcl variable. If you use the extension within the AlphaX editor (version 8.0b11 or greater), you can also install it in the Tclextensions directory located inside the application bundle.

REQUIREMENTS AND PORTABILITY

This extension is only useful on Macintosh platforms. Version 10.2 or greater of the system is required: the AddressBook framework was introduced in version 10.2 of the System (aka Jaguar).

KNOW ISSUES

Tcladdressbook was written by Bernard Desgraupes. Please e-mail any bug or problem you encounter: <bdesgraupes@users.sourceforge.net>

SOURCE CODE

Tcladdressbook is an Open Source Project. Its source code is public and can be found on the SourceForge site at the following address:

 <http://sourceforge.net/projects/tcladdressbook>

 Tcladdressbook binary releases are available at

  <http://sourceforge.net/project/showfiles.php?group_id=96169> or on my web page at

  <http://pagesperso-orange.fr/bdesgraupes/tcl.html>

 The code is under Subversion control. You can retrieve the latest stage of development using any Subversion client. See instructions at:

 <http://sourceforge.net/svn/?group_id=96169>

 You can also browse the Subversion repository online at

 <http://tcladdressbook.svn.sourceforge.net/viewvc/tcladdressbook/>

CONTRIBUTIONS

Code contributions (Tcl scripts making use of the Tcladdressbook extension) are very welcome. There is a "Contribs" directory in the Tcladdressbook project on SourceForge for code contributions. They must be free software, distributed under an Open Source license acceptable by the SourceForge site (for instance, the same licensing terms as the Tcl language itself).

LICENSE AND DISCLAIMER

This software is free software and distributed under the same licensing terms as the Tcl language itself. See license.terms in the Tcl distribution.

 (c) Copyright Bernard Desgraupes 2003-2009

SEE ALSO

See the TclX extension for keyed lists: TclX(n). See the Mk4Tcl extension for commands to open the database file directly.

KEYWORDS

Address book, data base.