Archive of articles classified as' "Address Book"

Back home

Address Book: Normale Gruppen von Smart-Groups unterscheiden

15/01/2012
In den Adress-Buch-Funktionsverzeichnis gibt es als Property nur den Namen und leider keinen Wert den man auslesen könnte, um zu erkennen, ob es sich um eine Smart-Group oder eine echte Gruppe handelt. Um das nun doch zu können sind zumindest die jeweiligen IDs der Gruppe recht eindeutig und enden ggf. mit dem String "SmartGroup". Möchte man zum Beispiel alle Namen der normalen Gruppe:

tell application "Address Book"

set groupnames to name of every group whose id does not end with "SmartGroup"

end tell

No Comments

Adressbuch: checkt ob eine Telefonnummer bereits vorhanden ist

30/06/2011
Das ist nur als Beispiel gedacht, wie so eine Funktion aussehen könnte:

tell application "Address Book"

activate

set my_phone_2_check to text returned of (display dialog "Telefonnummer:" default answer "0")

set allp to people

set phone_numbers to value of every phone of people

repeat with i from 1 to count of phone_numbers

set current_phone_numbers to item i of phone_numbers

if (count of current_phone_numbers) > 0 then

repeat with phone_number_2_check in current_phone_numbers

set phone_number_2_check to phone_number_2_check as text

if phone_number_2_check starts with "+" then

set phone_number_2_check to ("0" & characters 4 through -1 of phone_number_2_check) as text

end if

if phone_number_2_check contains " " then

set phone_number_2_check to my replace_chars(phone_number_2_check, " ", "")

end if

if phone_number_2_check contains "-" then

set phone_number_2_check to my replace_chars(phone_number_2_check, "-", "")

end if

if phone_number_2_check contains "/" then

set phone_number_2_check to my replace_chars(phone_number_2_check, "/", "")

end if

if phone_number_2_check = my_phone_2_check then

set selection to item i of people

error "Die Nummer gibt es schon"

end if

end repeat

end if

end repeat

end tell

to replace_chars(this_text, search_string, replacement_string)

try

if this_text contains the search_string then

set AppleScript's text item delimiters to the search_string

set the item_list to every text item of this_text

set AppleScript's text item delimiters to the replacement_string

set this_text to the item_list as string

set AppleScript's text item delimiters to ""

end if

return this_text

on error msg

error "error on replace_chars" & return & msg

end try

end replace_chars

No Comments

Addressbuch: Einzelne vCards exportieren

6/02/2011
Wenn man im Apple Adressbuch Kontakte als vCard exportieren möchte, erstellt das Programm bei mehreren Kontakten anscheinend immer nur eine Datei, in der alle Informationen stehen... FALSCH, mit gedrückter alt-Taste erstellt das Programm auf Wunsch auch separate VCF-Dateien für jeden Kontakt (siehe Kommentare).... somit kann man sich das Weiterlesen eigentlich sparen...Nun, dieses Skript (quick&dirty) exportiert die Kontakte in einzelne .vcf Dateien

-- hubionmac.com 06.02.2011

-- quick&dirty script for exporting contacts as single vCards

--exisiting vCards will not be overwritten by the script, instead new files will 

--get an index like "John Smith 1.vcf"


set doThese to get_item_2_process(true)

tell application "Address Book"

set destination_path to choose folder with prompt "Destination folder for export:"

repeat with doThis in doThese

if first name of doThis is missing value then

set firstname to ""

else

set firstname to first name of doThis

end if

if last name of doThis is missing value then

set lastname to ""

else

set lastname to last name of doThis

end if

if (lastname & firstname) as text = "" then

set namestring to "nobody.vcf"

else

set namestring to (first name of doThis & " " & last name of doThis & ".vcf") as text

end if

set namestring to my checkname_with_pdf_suffix(namestring, destination_path, false)

my writeToFile((destination_path as text) & namestring as text, (get vcard of doThis), false)

end repeat

my display_message(((count of doThese) & " contact(s) exported") as text, 3)

end tell





on writeToFile(MacFilePathTxt, txt, add2eof)

--lastedit 18.01.2011

if add2eof is false then

try

do shell script "rm " & quoted form of POSIX path of (MacFilePathTxt as alias)

end try

end if

set RefNum to (open for access file MacFilePathTxt with write permission)

try

if add2eof is false then

write txt to RefNum

else

write txt to RefNum starting at ((get eof RefNum) + 1)

end if

close access RefNum

return true

on error

close access RefNum

return false

end try

end writeToFile



to get_item_2_process(askwhat)

try

tell application "Address Book"

activate

tell application "System Events"

keystroke "0" using command down --show address-window not matter what...

end tell

if askwhat is true then

set theaction to button returned of (display dialog "Process all or just selection?" buttons {"All", "Selection", "cancel"} default button {"Selection"})

if theaction = "Selection" then

set a to every person whose selected is true

else

set a to people

end if

else

set a to people

end if

end tell

on error msg

error "error on get_item_2_process" & return & msg

end try

end get_item_2_process



to checkname_with_pdf_suffix(n, D, looped)

--check if filename exists in D

-- so if "A File.pdf" exists it names it "A File 1.pdf","A File 2.pdf",...

tell application "Finder"

set thefiles to name of every item of (D as alias)

end tell

if thefiles contains n then

if looped = false then

set n to ((characters 1 through -5 of n) & " 1" & (characters -4 through -1 of n)) as text

my checkname_with_pdf_suffix(n, D, true)

else

set tmp to (last word of ((characters 1 through -5 of n) as text) as integer)

set tmpcount to (count of characters of (tmp as text)) + 5

set tmp to tmp + 1

set n to ((characters 1 through (-1 * tmpcount) of n) & tmp & (characters -4 through -1 of n)) as text

my checkname_with_pdf_suffix(n, D, true)

end if

else

return n

end if

end checkname_with_pdf_suffix


on display_message(msgTXT, msgTimeout)

tell application "System Events"

set isRunning to ¬

(count of (every process whose name is "GrowlHelperApp")) > 0

end tell

if isRunning = true then

tell application "GrowlHelperApp"

-- Make a list of all the notification types 

-- that this script will ever send:

set the allNotificationsList to ¬

{"Status"}

-- Make a list of the notifications 

-- that will be enabled by default.      

-- Those not enabled by default can be enabled later 

-- in the 'Applications' tab of the growl prefpane.

set the enabledNotificationsList to ¬

{"Status"}

-- Register our script with growl.

-- You can optionally (as here) set a default icon 

-- for this script's notifications.

register as application ¬

"Address Book" all notifications allNotificationsList ¬

default notifications enabledNotificationsList ¬

icon of application "Address Book"

--Send a Notification...

notify with name ¬

"Status" title ¬

"Status" description ¬

msgTXT application name ¬

"Address Book"

return true

end tell

else

activate

display dialog msgTXT giving up after msgTimeout

end if

end display_message

2 Comments

Adressbuch: Wer war noch einmal Frida Henkemeier?

6/02/2011

Ich brauchte zum testen einer optimierten Version eines Dubletten-Skripts unbedingt über 7000 Adressen, die mitunter auch mal doppelt vorkommen. Da ich nicht einmal ansatzweise so viele Personen in meiner Datenbank habe, musste halt ein Skript meinen Bekanntenkreis erweitern.

Read the rest of this article »
2 Comments

Hubi’s Address Book Scripts

24/04/2010

Ich wurde von einem Leser dieses Blogs gebeten einige Skripte zu schreiben, da er sich seine Adressbuch-Datenbank mit vielen doppelten und Falschen Einträgen etwas zerschossen hatte. Dabei sind einige allgemeine Skripte entstanden, die ähnlich der iTunes Scripte einem Helfen das zu Skripten, was dass Apple Adressbuch nicht von selber tut. Dabei handelt es sich um ein Sammlung in der sich erstmal eine Skript-Bibliothek für häufig benutzt Funktionen angelegt habe.
Die Installation übernimmt ein kleines Script, welches auch gleich das AppleScript-Menü aktiviert, sofern noch nicht geschehen. Ich habe in die Library einen kleiner Version-Check eingebaut. Der (wenn nicht in den letzten 24h bereits geschehen) hier nachsieht, ob es eine neuere Version gibt. Bei dem Ding handelt es sich noch um die erste Version, also bitte Nachsicht und Fehler/Verbesserungen bitte gleich in Comments =)

Ich denke die Bezeichnungen der Skripte beschreiben deren jeweilige Funktionsweise wohl ausreichend =)

Update 16.01.2011

Ich habe die Bezeichnung der Skripte etwas verändert, hier und da etwas korrigiert, den Installer verbessert und eine Skript hinzugefügt, welches Duplikate in einer Gruppe sammelt.

Nur um das noch einmal klarzustellen:
Macht einen Backup eurer Adressen, die Nutzung der Skripte geschieht auf eigene Gefahr!!!

Die Skripte mit Installer also hier:

16 Comments

AppleScript: Search&Replace im Adressbuch

14/03/2010
Vielleicht auch praktisch, das Ding durchsucht Adressen im Adressbuch nach Zeichen (im Code werden Zeilenumbrüche ersetzt) in den Adress-Feldern und löscht diese. :-?
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

--script to remove certain characters/strings from an address

set toBeRemoved to {"

"}

tell application "Address Book"

set my_selections to selection

repeat with my_selection in my_selections

repeat with i from 1 to count of every address of my_selection

repeat with current_replace_string in toBeRemoved

set current_replace_string to current_replace_string as text

set street of address i of my_selection to my replace_chars((street of address i of my_selection), current_replace_string, "")

set city of address i of my_selection to my replace_chars((city of address i of my_selection), current_replace_string, "")

set zip of address i of my_selection to my replace_chars((zip of address i of my_selection), current_replace_string, "")

set country of address i of my_selection to my replace_chars((country of address i of my_selection), current_replace_string, "")

set state of address i of my_selection to my replace_chars((state of address i of my_selection), current_replace_string, "")

end repeat

end repeat

end repeat

save

end tell

to replace_chars(this_text, search_string, replacement_string)

if this_text contains the search_string then

set AppleScript's text item delimiters to the search_string

set the item_list to every text item of this_text

set AppleScript's text item delimiters to the replacement_string

set this_text to the item_list as string

set AppleScript's text item delimiters to ""

end if

return this_text

end replace_chars

No Comments

AppleScript: Adressbuch doppelte Adressen löschen

13/03/2010
Das Problem bei vielen Adressen in Apple-Adressbuch sind weniger Doppelte Einträge (Personen), diese lassen sich auch relativ leicht ausfindig machen, schließlich stehen die Namen ja direkt untereinander. Vielmehr doppelte Anschriften können ein Problem sein, wenn man Adressen von mehren Quellen im Adressbuch zusammenführt... Ich vermute mal, was war zumindest der Grund für das Problem aus diesem Thread.
Die Lösung dazu ist ein kleines AppleScript, welches die ausgewählten Einträge im Adressbuch auf doppelte Anschriften untersucht. Dabei ist besonders die Routine zum entfernen "unsichtbarer" Leerzeichen nützlich, die in Einem Text mehrere aufeinander folgende Leerzeichen bzw. am Anfang oder am Ende einer Zeile löscht.

Code zum markieren einmal anklicken Code im Skript-Editor öffnen

--remove dupilcated addresses in address-book that occure within ONE person

-- so this script does not replace duplicated persons, but a person's duplicated addresses =)!

-- USE THIS AT YOUR OWN RISK! MAKE A BACKUP BEFORE YOU APPLY IT TO YOUR ADDRESS BOOK!!!


tell application "Address Book"

set deleted_counter to 0

set ll to 0

set my_selections to selection

repeat with my_selection in my_selections

set ll to ll + 1

set current_addresses to {}

if (count of every address of my_selection) > 1 then

repeat with i from 1 to (count of every address of my_selection)

set current_address_string to my delete_space(formatted address of address i of my_selection)

if current_address_string is not in current_addresses then

set current_addresses to current_addresses & current_address_string

else

delete address i of my_selection

set deleted_counter to deleted_counter + 1

end if

end repeat

end if

end repeat

save

end tell

display dialog deleted_counter & " duplicated address-entries have been deleted (" & ll & " persons proccessed)" as text


to delete_space(thestring)

--delete every double-space...

set AppleScript's text item delimiters to " "

set theparts to every text item of thestring

set AppleScript's text item delimiters to ""

set finalparts to {}

repeat with t in theparts

if t as text is not "" then

set finalparts to finalparts & t

end if

end repeat

set AppleScript's text item delimiters to " "

set theparts to finalparts as text

set AppleScript's text item delimiters to ""

--replace spaces at the end of line (if new line comes after it) +++and at beginning

return replace_chars(replace_chars(theparts, " 

", "

"), "

 ", "

")

end delete_space


to replace_chars(this_text, search_string, replacement_string)

if this_text contains the search_string then

set AppleScript's text item delimiters to the search_string

set the item_list to every text item of this_text

set AppleScript's text item delimiters to the replacement_string

set this_text to the item_list as string

set AppleScript's text item delimiters to ""

end if

return this_text

end replace_chars

bla
No Comments