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
+20 -9
View File
@@ -22,10 +22,16 @@ property defaultWriteDebugLog : false
property defaultMailBodyFolderName : "mail_vorlagen"
property defaultMailBodyRecordName : "belegversand"
property defaultDryRunPreviewPath : "/tmp/DT-Belegversand-preview.txt"
property appVersion : "1.4"
property basePath : "/Library/Application Scripts/com.devon-technologies.think/Menu/Belegversand"
property configGroupName : "_config"
property configRecordName : "belegversand.conf"
property debugLogPath : "/tmp/DT-Belegversand-debug.log"
property windowTitle : "Belegversand, Vers. " & appVersion
property cfgConfigRecordUUID : missing value
property cfgMailToDefault : missing value
property cfgMailCcToDefault : missing value
@@ -505,19 +511,24 @@ on loadConfig()
end loadConfig
on runTemplateSelector()
set basePath to (do shell script "echo ~") & "/Library/Application Scripts/com.devon-technologies.think/Menu/Belegversand_1-4"
set basePath to (do shell script "echo ~") & basePath
set scriptPath to basePath & "/Helpers/show_mail_templates.scpt"
my writeDebug("Versuche Template-Script zu laden: " & scriptPath)
try
set loadedScript to load script (POSIX file scriptPath as alias)
my writeDebug("Template-Script geladen, starte jetzt...")
set templateResult to run loadedScript
my writeDebug("Template-Script fertig. Rueckgabe: '" & templateResult & "'")
set standaloneMode of loadedScript to false
-- DEBUG
-- display dialog "standaloneMode gesetzt auf: false" buttons {"OK"}
set templateResult to selectTemplate() of loadedScript
-- DEBUG
-- display dialog "templateResult: " & templateResult buttons {"OK"}
return templateResult
on error errMsg
my writeDebug("FEHLER in runTemplateSelector: " & errMsg)
display dialog "FEHLER: " & errMsg buttons {"OK"}
return ""
end try
end runTemplateSelector
@@ -838,7 +849,7 @@ on run
if (count of toSend) is 0 then error "Alle ausgewählten Belege sind bereits als versendet markiert und werden übersprungen."
set drChoice to button returned of (display dialog "Modus waehlen:" buttons {"Dry Run", "Senden (Entwurf erstellen)", "Abbrechen"} default button "Dry Run")
set drChoice to button returned of (display dialog windowTitle & return & return & "Modus waehlen:" buttons {"Dry Run", "Senden (Entwurf erstellen)", "Abbrechen"} default button "Dry Run")
if drChoice is "Abbrechen" then
my writeDebug("User hat Abbrechen geklickt")
@@ -867,7 +878,7 @@ on run
set previewPath to my writeDryRunPreviewFile(toSend, theTo)
set dryRunText to my dryRunSummaryText(toSend, previewPath)
set dryRunChoice to button returned of (display dialog dryRunText buttons {"OK", "Liste im Finder zeigen"} default button "OK")
set dryRunChoice to button returned of (display dialog windowTitle & return & return & dryRunText buttons {"OK", "Liste im Finder zeigen"} default button "OK")
if dryRunChoice is "Liste im Finder zeigen" then
my showDryRunPreviewInFinder(previewPath)
end if
@@ -53,6 +53,7 @@ property requiredConfigKey : "BELEGE_ROOT_UUID="
property mainScriptName : "_belegversand.scpt"
-- Versionsinformation für README und Hinweise.
property appVersion : "1.4"
property basePath : "/Library/Application Scripts/com.devon-technologies.think/Menu/Belegversand"
-- Default-Werte für die Erstkonfiguration.
property defaultMailTo : "steuer@name.de"
property defaultSubjectPrefix : "Unterlagen"
@@ -62,6 +63,69 @@ property defaultSentTagForDocs : "gesendet"
property defaultWriteDebugLog : "false"
property defaultShowReadme : "true"
property defaultDryRunPreviewPath : "/tmp/DT-Belegversand-preview.txt"
(*
compileAllScripts(basePath)
--------------------------
Kompiliert alle AppleScript-Quellen (.applescript) zu ausführbaren Scripts (.scpt).
WARUM:
- Im Git-Repo liegen nur .applescript-Dateien (Plaintext für Versionskontrolle)
- AppleScript kann aber nur .scpt-Dateien (kompiliert) laden via "load script"
- Nach git clone sind nur .applescript vorhanden → kein Versand möglich
WAS:
- Iteriert über alle 6 Scripts im Projekt
- Ruft osacompile auf (macOS Tool)
- Liest .applescript-Quelle
- Schreibt .scpt-Binary
- Löscht die .applescript danach (sauberer: nur .scpt bleibt)
PFAD-PROBLEM:
- basePath MUSS absolut sein (ab Home, mit do shell script "echo ~")
- Relative Pfade funktionieren nicht zuverlässig in AppleScript
- Deshalb wird basePath als Parameter übergeben, nicht lokal definiert
WICHTIG:
- Diese Funktion wird nur beim Setup aufgerufen (nach git clone)
- Sie ist kein Fehler, wenn .applescript nicht existiert (z.B. bei AirDrop-Kopie)
*)
on compileAllScripts(basePath)
tell application id "DNtp"
my writeDebug("compileAllScripts: Start")
end tell
set filesToCompile to {"START.applescript", ¬
"Helpers/show_mail_templates.applescript", ¬
"Helpers/create-year-cycle.applescript", ¬
"Helpers/uuid_anzeigen.applescript", ¬
"Helpers/scripts/_belegversand_setup.applescript", ¬
"Helpers/scripts/_belegversand.applescript"}
repeat with fileName in filesToCompile
set sourceFile to basePath & "/" & fileName
set outputFile to basePath & "/" & (text 1 thru -13 of fileName) & ".scpt"
try
do shell script "osacompile -o " & quoted form of outputFile & " " & quoted form of sourceFile
-- Nach Kompilierung: .applescript löschen
do shell script "rm " & quoted form of sourceFile
tell application id "DNtp"
my writeDebug("Compiled & removed: " & filename)
end tell
on error errMsg
tell application id "DNtp"
my writeDebug("Compile ERROR: " & filename & " - " & errMsg)
end tell
end try
end repeat
tell application id "DNtp"
my writeDebug("compileAllScripts: Done")
end tell
end compileAllScripts
(*
runSiblingScript(scriptFileName)
--------------------------------
@@ -73,7 +137,7 @@ Verwendung:
*)
on runSiblingScript(scriptFileName)
-- Absolute Basis-Path (Home + fest Installation)
set basePath to (do shell script "echo ~") & "/Library/Application Scripts/com.devon-technologies.think/Menu/Belegversand_1-4"
set basePath to (do shell script "echo ~") & basePath
set targetPath to basePath & "/Helpers/scripts/" & scriptFileName
try
@@ -230,6 +294,7 @@ Freie Kommentar- oder Trennerzeilen sind daher unproblematisch.
on buildConfigText(mailToDefault, mailCcToDefault, subjectPrefix, zipPasswordDefault, logSentGroupName, belegeRootUUID, writeDebugLogValue, showReadmeValue, readmeUUID, mailBodyFolderName, mailBodyRecordName, sentTagForDocs, dryRunPreviewPath)
return "## Benutzer-Einstellungen - bitte individuell anpassen." & return & ¬
"## Eine Kurz-Doku findest du in der Datei README-Belegversand.md" & return & return & ¬
"APP_VERSION=" & appVersion & return & ¬
"MAIL_TO_DEFAULT=" & mailToDefault & return & ¬
"MAIL_CC_TO_DEFAULT=" & mailCcToDefault & return & ¬
"MAIL_SUBJECT_PREFIX=" & subjectPrefix & return & ¬
@@ -612,6 +677,18 @@ on run
set debugInfoText to ""
end if
if writeDebugLogValue is "true" then
set debugInfoText to return & return & "Debug-Log: /tmp/DT-Belegversand-debug.log"
else
set debugInfoText to ""
end if
-- Absolute Basis-Path für Script-Kompilierung
set basePath to (do shell script "echo ~") & basePath
compileAllScripts(basePath)
set compileHint to return & return & "✓ Scripts kompiliert"
display dialog "Belegversand wurde eingerichtet." & return & return & ¬
"Datenbank-Wurzel: " & dbRootName & return & ¬
"Belege-Gruppe: " & belegeRootName & return & ¬
+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()
+8 -3
View File
@@ -28,6 +28,12 @@ property setupScriptName : "_belegversand_setup.scpt"
property configGroupName : "_config"
-- Name der eigentlichen Konfigurationsdatei in DEVONthink.
property configRecordName : "belegversand.conf"
property appVersion : "1.4"
property basePath : "/Library/Application Scripts/com.devon-technologies.think/Menu/Belegversand"
property windowTitle : "Belegversand, Vers. " & appVersion
(*
runSiblingScript(scriptFileName)
--------------------------------
@@ -36,7 +42,7 @@ Parameter:
- scriptFileName : Dateiname des aufzurufenden Scripts, z. B.
"_belegversand_setup.scpt"
Ablauf:
- absolute Basis-Path setzen (Home + fest Pfad zu Belegversand_1-4)
- absolute Basis-Path setzen
- daran den Unterordner "Helpers/scripts" und den Dateinamen anhängen
- prüfen, ob die Scriptdatei existiert
- Script laden
@@ -50,8 +56,7 @@ Der absolute Pfad ist invariant und unabhängig vom Speicherort dieses Scripts.
*)
on runSiblingScript(scriptFileName)
-- Absolute Basis-Path (Home + fest Installation)
set basePath to (do shell script "echo ~") & "/Library/Application Scripts/com.devon-technologies.think/Menu/Belegversand_1-4"
set targetPath to basePath & "/Helpers/scripts/" & scriptFileName
set targetPath to (do shell script "echo ~") & "/" & basePath & "/Helpers/scripts/" & scriptFileName
try
set targetAlias to POSIX file targetPath as alias