Mac::Glue::Apps::AddressBookExport - Export from Address Book and publish


  use Mac::Glue::Apps::AddressBookExport;
  my $exporter = Mac::Glue::Apps::AddressBookExport->new({
    'glue_name'       => 'Address Book',
    'template_dir'    => '/path/to/template_dir/',
    'out_dir'         => '/where/to/write/out/pages_dir/',
    'skip_with_image' => 1,

This will generate an index page (with names and phone numbers) in your 'out_dir'. It will also create 'out_dir/people/<letter>.html' which will be all those people who's name starts with that letter, showing name, phone numbers, emails and addresses.


This package uses Mac::Glue to export all vCards from your Apple Address Book. I can write this file to disk, or process the results using Text::vCard and Template Toolkit to generate web pages.


  my $exporter = Mac::Glue::Apps::AddressBookExport->new({
    'glue_name'       => 'Address Book',
    'template_dir'    => '/path/to/template_dir/',
    'out_dir'         => '/where/to/write/out/pages_dir/',
    'skip_with_image' => 1,

All options can be set here, rather than having to be passed to each method, but equally options can be set as each method is called (overwriting what is already in the object). This constructor doesn't actually do anything other than store the options submitted to it and return the object.

See the examples directory for template examples.


        'glue_name'     => 'Address Book', # Default

        # Optional dump of vcard file
        'out_file' => '/full/path/to/outfile.vcf',
        # Generate templates
        'template_dir' => '/path/to/template_dir/',
        'out_dir' => '/where/to/write/out/pages_dir/',

The out_file will be version 3.0 of the vCard spec, you can use Text::vCard::Addressbook to parse this.

If 'template_dir' and 'out_dir' are specified then the generate_web_pages() will be called after the address book has been exported.


    'template_root' => '/path/to/template/dir',
    'out_dir'       => '/path/results/printed/to',
    'vcards'        => $vcard_data,

This method is called automatically from export_address_book() if 'template_root' and 'out_dir' have been specified.

The template_dir should contain 'index.html' and 'by_name.html' template (see examples directory of this package for a starting point), but it will check and just not process if they are missing.

'vcards' will have already been populated if export_address_book() has been called. Alternativly you can supply the vcard data which is submitted to Text::vCard::Addressbook as source_text.


  my $vcards = $exporter->get_vcards_from_addressbook({
    'skip_with_image' => 1,
    'glue_name'       => 'Address Book',

This is the method which calls Mac::Glue and extracts the vcard information from Apples Address Book.

'skip_with_image' is there so that and person with an image associated can be skipped on the export. This is because Text::vCard can not support it currently.

The glue_name defaults to 'Address Book', but as you can set it when you create your glue (see Mac::Glue) this option allows you to overwrite the default.


This is a function, NOT a method.

  my $first_letter = get_first_letter_from_vcard($vcard,'fullname');

This function can take two arguments. The First must be a Text::vCard object. The second is optional (defaulting to 'fullname') which is the method to call on the object. The first letter of the return value from the method is then returned upper cased.

This is used to sort which page each person is put on and in the template to generate the links for each person and which letters are active.


One could extend this package to upload the vCard file to a server and have that then generate webpages, but for now that's an exercise for the user! I'm just going to rsync my pages up. If anyone wants to extend this to inserting info into a DB or something else please let me know.


Leo Lapworth,


Copyright (c) 2005 Leo Lapworth. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


Mac::Glue Text::vCard Template