(* show_mail_templates.scpt – Version 1.0 Rolle dieses Scripts -------------------- Dieses Helferlein listet alle verfügbaren Mail-Vorlagen aus /mail_vorlagen auf und lässt den User eine davon via "choose from list" auswählen. Rückgabe: - Name der gewählten Vorlage-Datei - Oder: leerer String, wenn User abbricht oder keine Vorlagen vorhanden Verwendung: Das Script wird vom Hauptscript _belegversand.scpt aufgerufen, um dem User bei mehreren Mail-Vorlagen eine Auswahl zu bieten. Behavior: - 0 Vorlagen: leer zurück - 1 Vorlage: direkt diese zurück (kein Dialog) - >1 Vorlagen: choose from list Dialog *) tell application id "DNtp" set sel to selection if sel is {} then error "Bitte zuerst ein Objekt in DEVONthink auswählen." end if set selectedRecord to item 1 of sel end tell (* getTopParentGroup(theRecord) ---------------------------- Ermittelt die DB-Wurzel relativ zu einem Record. *) on getTopParentGroup(theRecord) tell application id "DNtp" set currentRecord to theRecord repeat try set p to parents of currentRecord if p is {} then return currentRecord set currentRecord to item 1 of p on error return currentRecord end try end repeat end tell end getTopParentGroup (* findChildByName(parentRecord, childName) ---------------------------------------- Sucht ein Kind-Record nach Name. *) on findChildByName(parentRecord, childName) tell application id "DNtp" try set kids to children of parentRecord repeat with i from 1 to count of kids set c to item i of kids if (name of c as rich text) is childName then return c end repeat end try end tell return missing value end findChildByName -- Hauptlogik set dbRoot to getTopParentGroup(selectedRecord) set configGroup to findChildByName(dbRoot, "_config") if configGroup is missing value then error "Keine _config-Gruppe gefunden." end if set mailTemplatesGroup to findChildByName(configGroup, "mail_vorlagen") if mailTemplatesGroup is missing value then error "Keine mail_vorlagen-Gruppe gefunden." end if -- Alle Dateien in mail_vorlagen auflisten tell application id "DNtp" set templateChildren to children of mailTemplatesGroup end tell if templateChildren is {} then -- Keine Vorlagen vorhanden → leerer String return "" end if -- Dateinamen sammeln set templateNames to {} repeat with eachTemplate in templateChildren set templateName to (eachTemplate's name) & "" set end of templateNames to templateName end repeat -- Wenn nur eine Vorlage: diese direkt zurückgeben (kein Dialog) if (count of templateNames) is 1 then return item 1 of templateNames end if -- Wenn mehrere Vorlagen: User wählen lassen set chosenTemplate to choose from list templateNames with title "Mail-Vorlage(n)..." with prompt "Folgende Vorlagen gefunden:" if chosenTemplate is false then -- User hat abgebrochen → leerer String return "" else -- Rückgabe: Name der gewählten Vorlage return item 1 of chosenTemplate end if