show_mail_templates unterscheidet jetzt zwischen Aufruf aus dem Menü autonom) oder Aufruf auf _belegversand.applescript. Probelm danach: In _belegversand wird show_mail_templates entweder als *.scpt (kompiliert) oder *.applescript (Textdatei) aufgerufen. Dateiendungen müssen demnach angepasst werden. Daher Einführung der neuen Funktione on compileAllScripts(basePath) in der Datei _belegversand_setup.applescript.

This commit is contained in:
2026-08-15 20:14:34 +02:00
parent 49291fc2d3
commit 7acdfe8927
4 changed files with 186 additions and 81 deletions
+80 -68
View File
@@ -1,23 +1,22 @@
(*
show_mail_templates.scpt – Version 1.0
show_mail_templates.applescript – Version 1.4.1
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.
Listet alle verfügbaren Mail-Vorlagen aus /mail_vorlagen auf
und lässt den User eine davon 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.
Property standaloneMode:
- true (default): Script läuft alleine, User-freundlich
- false: Aufgerufen von _belegversand, minimal intrusive
Behavior:
- 0 Vorlagen: leer zurück
- 1 Vorlage: direkt diese zurück (kein Dialog)
- >1 Vorlagen: choose from list Dialog
- 0 Vorlagen (standalone): Dialog "mail_vorlagen ist leer"
- 0 Vorlagen (nicht standalone): leerer String
- 1 Vorlage (standalone): Dialog mit Vorlage-Name
- 1 Vorlage (nicht standalone): direkt zurückgeben
- >1 Vorlagen: choose from list Dialog (immer)
*)
property standaloneMode : true
tell application id "DNtp"
set sel to selection
@@ -28,11 +27,6 @@ tell application id "DNtp"
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
@@ -49,11 +43,6 @@ on getTopParentGroup(theRecord)
end tell
end getTopParentGroup
(*
findChildByName(parentRecord, childName)
----------------------------------------
Sucht ein Kind-Record nach Name.
*)
on findChildByName(parentRecord, childName)
tell application id "DNtp"
try
@@ -67,49 +56,72 @@ on findChildByName(parentRecord, childName)
return missing value
end findChildByName
-- Hauptlogik
set dbRoot to getTopParentGroup(selectedRecord)
set configGroup to findChildByName(dbRoot, "_config")
on selectTemplate()
-- Im Standalone-Modus: Erste DB nutzen statt Selection
if standaloneMode then
tell application id "DNtp"
set allDatabases to databases
if allDatabases is {} then
error "Keine DEVONthink-Datenbank offen."
end if
set selectedRecord to item 1 of allDatabases
end tell
else
-- Von _belegversand aufgerufen: aktuelle Selection nutzen
tell application id "DNtp"
set sel to selection
if sel is {} then
error "Keine Objekte ausgewählt."
end if
set selectedRecord to item 1 of sel
end tell
end if
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
tell application id "DNtp"
set templateChildren to children of mailTemplatesGroup
end tell
set templateNames to {}
repeat with eachTemplate in templateChildren
set templateName to (eachTemplate's name) & ""
set end of templateNames to templateName
end repeat
-- EDGE CASE: 0 Vorlagen
if templateNames is {} then
if standaloneMode then
display dialog "Die DEVONthink-Gruppe /mail_vorlagen ist leer." buttons {"OK"} default button "OK"
end if
return ""
end if
-- EDGE CASE: 1 Vorlage
if (count of templateNames) is 1 then
if standaloneMode then
display dialog "Folgende Mail-Vorlage gefunden:" & return & return & (item 1 of templateNames) buttons {"OK"} default button "OK"
end if
return item 1 of templateNames
end if
-- NORMAL: >1 Vorlagen
set chosenTemplate to choose from list templateNames with title "Mail-Vorlage(n)..." with prompt "Folgende Vorlagen gefunden:"
if chosenTemplate is false then
return ""
else
return item 1 of chosenTemplate
end if
end selectTemplate
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
-- Wenn standalone aufgerufen
selectTemplate()