Showing posts with label mac os x. Show all posts
Showing posts with label mac os x. Show all posts

Wednesday, November 19, 2014

How to export Mac's Address Book contents to simple kind-of-human-readable dump

Recently I wanted to take a dump of Mac’s Address Book contents. Just the names & addresses of my contacts in a human-readable format.

Some background

First, my Address Book version is 5.0.3. It has the functionality File → Export -> Address Book Archive. This command generates a directory that contains a file with .abcddb postfix that is a SQLite file. (In my case, the file name was AddressBook-v22.abcddb)

After that, I found the blog post AddressBook entries from a Mac using SQLite that has the needed SQL query with the columns and the joins sorted out.

To get the output to a file, a couple of SQLite commands were found from How to export the results of my query to csv file.

The result

The end result to be run with sqlite3 (a SQLite command-line utility). For all the possible columns, check the blog post linked above.

.headers on
.mode csv
.output export.csv

SELECT DISTINCT
ZABCDRECORD.ZFIRSTNAME [FIRST NAME],
ZABCDRECORD.ZLASTNAME [LAST NAME],
ZABCDPOSTALADDRESS.ZSTREET [STREET],
ZABCDPOSTALADDRESS.ZZIPCODE [ZIPCODE],
ZABCDPOSTALADDRESS.ZCITY [CITY]

FROM ZABCDRECORD
LEFT JOIN ZABCDPOSTALADDRESS on 
  ZABCDRECORD.Z_PK = ZABCDPOSTALADDRESS.ZOWNER
LEFT JOIN ZABCDNOTE ON 
  ZABCDRECORD.Z_PK = ZABCDNOTE.ZCONTACT

ORDER BY
ZABCDRECORD.ZLASTNAME,
ZABCDRECORD.ZFIRSTNAME;


.output stdout

Discussion

Note that entries containing newlines might need some cleanup (google for “sqlite replace newline”, for example) but that wasn’t needed in my case.

Wednesday, January 30, 2013

Ääkköset, merkistöt ja Mac OS X:n komentorivityökaluja

Eiväthän ääkköset enää ole ongelma

Muistiinpanoja sen varalta jos kuitenkin ovat, lähinnä Mac OS X:n komentorivin ja suomenkielisen tekstin yhteydessä.

Oleelliset merkistöt suomenkielisessä ympäristössä

  • UTF-8 : Unicoden vaihtelevanpituinen koodaustapa (1-4 tavua per merkki)
  • ISO 8859-1 (aka. Latin1) : 8-bittinen, eli 8 bittiä (1 tavu) per merkki -> 256 merkkipaikkaa

Tekstitiedoston merkistön tunnistaminen

Lähtökohtaisesti merkistöä ei voi päätellä tekstistä, vaan merkistön tulee olla sovittuna / etukäteen tiedossa. Kun tuntemattomalla merkistöllä koodattu tiedosto kuitenkin tulee vastaan, voidaan (varsinkin jos kielikonteksti on tuttu) tehdä erilaisia akateemisia arvauksia.

Tiedoston tavujen tarkastelu heksadumpista

Tiedostosta voidaan ottaa heksadumppi (jolloin nähdään tiedoston kukin tavu)
$ hexdump -C aeaekkoset-utf8.txt
00000000  c3 84 c3 a4 6b 6b c3 b6  73 74 65 73 74 69 0a     |....kk..stesti.|
0000000f
Olettaen että sana on "Ääkköstesti", on kyse UTF-8:stä. Sama sisältö Latin1-koodauksella:
$ hexdump -C aeaekkoset-latin1.txt
00000000  c4 e4 6b 6b f6 73 74 65  73 74 69 0a              |..kk.stesti.|
0000000c
Oleelliset ääkköset
Kirjain UTF-8 Latin-1
ä c3 a4 e4 (228)
ö c3 b6 f6 (246)
Ä c3 84 c4 (196)
Ö c3 96 d6 (214)

Automaattinen päättely (file-komento)

Hyvän akateemisen arvauksen saa myös komennolla file
$ file aeaekkoset-utf8.txt 
aeaekkoset-utf8.txt: UTF-8 Unicode text
Ja
$ file aeaekkoset-latin1.txt 
aeaekkoset-latin1.txt: ISO-8859 text

Merkistön vaihtaminen

Tekstitiedoston merkistön vaihtaminen onnistuu komennolla iconv.

Latin-1 -> UTF-8
$ iconv -f LATIN1 -t UTF-8 input_file > output_file
UTF-8 -> Latin-1
$ iconv -f UTF-8 -t LATIN1 input_file > output_file

Linkkejä

Monday, September 5, 2011

Samsung ML-1610 ja iMac

Sattumalta saatiin käyttöön tulostin, Samsung ML-1610. Suoraan ei nähtävästi valmistajalta löytynyt Mac OS X -ajureita (iMac ja Snow Leopard käytössä) mutta SpliX asentui sukkana sisään ja ainakin testisivu tuli moitteettomasti. Pistetäänpä ylös jos joku asiaa joskus googlettaa.