Webstatt.org - Community seit 2006 - 2012 (2024?)

MacOSX AddressBook vom Terminal

Avatar user-271
25.08.2009 05:12

Hab mal wieder was in reinem eigennutz geschrieben....
ein kleines script, unsauber geschrieben, aber tuts, um auf das Addressbuch im Mac zuzugreifen. Ich weiß noch nicht, wie sich das ganze auf einem multiusersystem verhält..aber nachdem jeder User seine eigene sqlite datenbank hat, sollte das kein problem sein lächeln

man sollte das alles mal in eine sql anfrage zusammenfassen...aber hatte dazu bisher keinen bock und hab das so nach und nach aufgebaut...deshalb die einzelnen anfragen ^^

naja, wers braucht...ich braucsh ab und an, weil mein mac zuhause steht und ich dann halt über ssh drauf zugreif um meine kontakte zu kriegen zwinkern

#!/usr/bin/php
<?php
$path = '/Users/'.trim(`whoami`).'/Library/Application Support/Addressbook/';

function simplifyLabel($label) {
return str_replace(array('_','$','!','<','>'zwinkern,'',$label);
}

function searchAddressBook($path,$search) {
$address = array();
$dbHandle = sqlite3_open($path.'AddressBook-v22.abcddb'zwinkern;
if(!$dbHandle) die("Could not open database..."zwinkern;
$resName = sqlite3_query($dbHandle,'SELECT * FROM ZABCDRECORD WHERE ZSORTINGFIRSTNAME LIKE "%'.$search.'%"'zwinkern;
while($rowName = sqlite3_fetch_array($resName)) {
$name = explode(' ',$rowName['ZSORTINGFIRSTNAME']);
$name = $name[2].' '.$name[3];

$address[$name]['Z_PK'] = $rowName['Z_PK'];

$resPhone = sqlite3_query($dbHandle,'SELECT * FROM ZABCDPHONENUMBER WHERE ZOWNER='.$rowName["Z_PK"]);
while($rowPhone = sqlite3_fetch_array($resPhone)) {
$address[$name]['phone'][] = array(
'label' => simplifyLabel($rowPhone['ZLABEL']),
'number' => $rowPhone['ZFULLNUMBER']
);
}

$resAddress = sqlite3_query($dbHandle,'SELECT * FROM ZABCDPOSTALADDRESS
WHERE ZOWNER='.$rowName["Z_PK"]);
while($rowAddress = sqlite3_fetch_array($resAddress)) {
$address[$name]['address'][] = array(
'city' => $rowAddress['ZCITY'],
'label' => simplifyLabel($rowAddress['ZLABEL']),
'region' => $rowAddress['ZREGION'],
'country' => $rowAddress['ZCOUNTRYNAME'],
'street' => $rowAddress['ZSTREET'],
'zipcode' => $rowAddress['ZZIPCODE']
);
}

$resEmail = sqlite3_query($dbHandle,'SELECT * FROM ZABCDEMAILADDRESS WHERE ZOWNER='.$rowName['Z_PK']);
while($rowEmail = sqlite3_fetch_array($resEmail)) {
$address[$name]['email'][] = array(
'label' => simplifyLabel($rowEmail['ZLABEL']),
'email' => $rowEmail['ZADDRESSNORMALIZED']
);
}

$resURL = sqlite3_query($dbHandle,'SELECT * FROM ZABCDURLADDRESS WHERE ZOWNER='.$rowName['Z_PK']);
while($rowURL = sqlite3_fetch_array($resURL)) {
$address[$name]['url'][] = array(
'label' => simplifyLabel($rowURL['ZLABEL']),
'url' => $rowURL['ZURL']
);
}
}

@sqlite3_close($dbHandle);

return $address;
}

$addressBook = searchAddressbook($path,$argv[1]);

foreach($addressBook as $key=>$elem) {
print $key."\n";

if(count($elem['phone']) > 0) {
print "\tPhone\n";
foreach($elem['phone'] as $e) {
print "\t\t".$e['label'].': '.str_repeat(' ',7-strlen($e['label'])).$e['number']."\n";
}
print "\n";
}

if(count($elem['address']) > 0) {
print "\n\tAddress\n";
foreach($elem['address'] as $e) {
print "\t\t".$e['label'].":\n";
print "\t\t".$e['street']."\n";
print "\t\t".$e['zipcode'].' '.$e['city']."\n";
print "\t\t".$e['country']."\n\n";
}
}

if(count($elem['email']) > 0) {
print "\tEmail\n";
foreach($elem['email'] as $e) {
print "\t\t".$e['label'].': '.$e['email']."\n";
}
}

print "\n\n";
}

lg, jan

#!/bin/bash
traurig){ neutral:& };: