PERL-Copy-Contacts

From Organic Design wiki
Revision as of 09:02, 6 August 2009 by Nad (talk | contribs)

<perl>

  1. !/usr/bin/perl
  2. Scan contacts in CWD, and copy email of contact to clipboard
  3. Separator character can be sent in command-line ("," is default)
  4. nad - 2005-04-29
  1. Requirements

use Win32; use Win32::Clipboard; use Cwd;

  1. Set up local environment

$clip = Win32::Clipboard(); $cwd = cwd; $separator = $#ARGV == 0 ? pop(@ARGV) : ","; @emails = (); @bad_links = (); @no_emails = ();

  1. Retrieve contacts' email addresses

if ($cwd =~ /(.+my organisation\/)/i) { my $contacts = "$1C - Contacts/"; opendir(DIR, cwd) || die "can't open CWD!"; for (grep /^C-.+$/i, readdir DIR) { s/.lnk$//i; s/^c-//i; my $contact = $_; my $opened = 1; opendir(CONTACT, $contacts."C-$contact") or $opened = 0; if ($opened == 1) { my @list = map {/(.+)\.url$/; "\"$contact\"<$1>";} grep /[@]+/, readdir CONTACT; $#list+1 ? push @emails, @list : push @no_emails, $contact; closedir CONTACT; } else {push @bad_links, $contact} } closedir DIR; }

  1. Report non-existent contacts

Win32::MsgBox(join("\n", @bad_links), MB_ICONEXCLAMATION, "Could not find the following contacts!") if $#bad_links+1;

  1. Report contacts without emails addresses

Win32::MsgBox(join("\n", @no_emails), MB_ICONINFORMATION, "The following contacts have no email address...") if $#no_emails+1;

  1. Copy to clipboard as separated list

$clip->Set( join $separator, @emails ); </perl>