Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • by pudge (1) on 2004.05.25 18:39 (#31081) Homepage Journal
    use Mac::Glue;
     
    my $ab = new Mac::Glue 'Address Book';
     
    my $people = $ab->obj('people');
    for my $person ($people->get) {
        for my $phone ($person->prop('phone')->get) {
            my $value  = $phone->prop('value');
            my $number = $value->get;
            if ($number =~ /whatever/) {
                $number = "whatever";
                $value->set(to => $number);
            }
        }
    }
    Not entirely tested, and it is incomplete, as I am not exactly sure how you want the number to be formatted. Just print "$number\n" after fetching to see all the values, and decide what you want to do with them from there.
    • pudge++

      This did the trick for me. Thanks!

      use Mac::Glue;

      # sudo gluemac /Applications/Address\ Book.app

      my $ab = new Mac::Glue 'Address Book';

      my $people = $ab->obj('people');
      for my $person ($people->get) {
          for my $phone ($person->prop('phone')->get) {
              my $value  = $phone->prop('value');
              my $number = $value->get;
              next if $number =~ /^41-/ || $number =~ /^0/;
              next

      • Great, glad it worked. I saw something about uninitialized values in IRC, did you figure that one out?
        • No, I just removed the -w from the shebang line. It was a one-off, and so not worth the effort to debug. Must've been a problem with the data in my address book...