(* -- Under the following circumstances -- the exports of Apple Addressbook.app -- (and the exports of PHP iAddressbook 0.98) -- lose the Categories/Group assignment: -- OS X 10.4.10 Tiger, Addressbook.app 4.0.5 -- This Script grabs the information out of -- the field «note», puts it back to the -- assignment and leaves the usual comments -- in the «note» field without the assignment -- information. -- Keywords: group, category, categories, -- addressbook, address book, import, export, -- assign, assignment, contact, vcf, vcards, -- transfer -- October 19, 2007 -- Script by Lucas Gross, www.luc.gr, www.idk.ch -- I do not take responsibily of any loss of data! -- Backup your AddressBook data before under: -- /Users//Library/Application Support/AddressBook -- or in Addressbook.app > File > Backup ... *) tell application "Finder" display dialog "Have you backuped your data? --- Please note that it runs probably longer than 5 min according to a big address library, so try it first with under hundred entries... " end tell tell application "Address Book" set strKeyCategory to "CATEGORIES:" repeat with objContact in every person set strNote to note of objContact -- Sonst ein Kommentar -- auf mehreren Zeilen, mit Kommas etc. -- CATEGORIES: IDK Basel,F LifeClipper2 Gestaltung,E IN3 Szenografie-Festival,IDK: In Projekt involvierte Mitarbeiter if strNote contains strKeyCategory then set strNoteLines to paragraphs of strNote -- return strNoteLines set strNewNote to "" repeat with i from 1 to (count every item of strNoteLines) of strNoteLines if item i of strNoteLines does not contain strKeyCategory then set strNewNote to strNewNote & item i of strNoteLines end if if item i of strNoteLines contains strKeyCategory then set strNoteCat to item i of strNoteLines set strNoteCat to my findAndReplace(strKeyCategory, "", strNoteCat) set defaultDelimiter to AppleScript's AppleScript's text item delimiters -- we need to remember the old value! set AppleScript's text item delimiters to "," -- delimiter character set strArray to strNoteCat's text items -- get a list of items: {" IDK Basel", "F LifeClipper2 Gestaltung", "E IN3 Szenografie-Festival"} set AppleScript's AppleScript's text item delimiters to defaultDelimiter -- SET defaultDelimiter BACK! repeat with i from 1 to (count every item of strArray) set strGroup to "" if item i of strArray is not " " then if i is 1 then -- return item i of strArray set strGroup to my chopString(item i of strArray) -- return strGroup else set strGroup to item i of strArray end if end if set item i of strArray to "" if strGroup is not "" then if not (group strGroup exists) then make new group at the end of groups with properties {name:strGroup} end if add objContact to group strGroup end if -- save addressbook end repeat if strNewNote is not "" then -- set strNewNote to my findAndReplace(" ", " ", strNewNote) -- replace double spaces set note of objContact to strNewNote else set note of objContact to "" end if -- save addressbook end if end repeat -- end repeat with i from 1 to (count every item of strNoteLines) of strNoteLines end if save addressbook end repeat -- end repeat with objContact in every person end tell on chopString(strIn) --set strIn to " Idk Basel " set firstChar to character 1 of strIn if firstChar is " " then set startStrpos to 2 else set startStrpos to 1 end if set lastChar to (character (count every character of strIn) of strIn) if lastChar is " " then set stopStrpos to (count every character of strIn) - 1 else set stopStrpos to (count every character of strIn) end if set strOut to text from character startStrpos to character stopStrpos of strIn return strOut end chopString on findAndReplace(tofind, toreplace, TheString) set ditd to text item delimiters set text item delimiters to tofind set textItems to text items of TheString set text item delimiters to toreplace if (class of TheString is string) then set res to textItems as string else -- if (class of TheString is Unicode text) then set res to textItems as Unicode text end if set text item delimiters to ditd return res end findAndReplace (* -- we don't need that -- ///// start trim first whitespace of strFirstGroup set AppleScript's text item delimiters to " " -- delimiter character set strFirstGroup to item 1 of strArray set strArrayFirstGroup to strFirstGroup's text items -- return strArrayFirstGroup set a to 1 set b to (count strArrayFirstGroup) -- array count -- {" ", "IDK", "Basel"} --> a will be 2 repeat while (a < b) and ((count item a of strArrayFirstGroup) is 0) -- check if array item is empty set a to a + 1 -- increment to the essiential array item with content end repeat -- strip trailing spaces repeat while (b > a) and ((count item b of strArrayFirstGroup) is 0) -- check if array item is empty set b to b - 1 -- decrement to the essiential array item with content end repeat set strNewFirstGroup to text from text item a to text item b of strFirstGroup set AppleScript's AppleScript's text item delimiters to defaultDelimiter -- SET defaultDelimiter BACK! set item 1 of strArray to strNewFirstGroup -- write the chopped string back to strArray -- ///// end trim first whitespace of strFirstGroup *)