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 defaultMailBodyFolderName : "mail_vorlagen"
property defaultMailBodyRecordName : "belegversand" property defaultMailBodyRecordName : "belegversand"
property defaultDryRunPreviewPath : "/tmp/DT-Belegversand-preview.txt" 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 configGroupName : "_config"
property configRecordName : "belegversand.conf" property configRecordName : "belegversand.conf"
property debugLogPath : "/tmp/DT-Belegversand-debug.log" property debugLogPath : "/tmp/DT-Belegversand-debug.log"
property windowTitle : "Belegversand, Vers. " & appVersion
property cfgConfigRecordUUID : missing value property cfgConfigRecordUUID : missing value
property cfgMailToDefault : missing value property cfgMailToDefault : missing value
property cfgMailCcToDefault : missing value property cfgMailCcToDefault : missing value
@@ -505,19 +511,24 @@ on loadConfig()
end loadConfig end loadConfig
on runTemplateSelector() 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" set scriptPath to basePath & "/Helpers/show_mail_templates.scpt"
my writeDebug("Versuche Template-Script zu laden: " & scriptPath)
try try
set loadedScript to load script (POSIX file scriptPath as alias) set loadedScript to load script (POSIX file scriptPath as alias)
my writeDebug("Template-Script geladen, starte jetzt...") set standaloneMode of loadedScript to false
set templateResult to run loadedScript
my writeDebug("Template-Script fertig. Rueckgabe: '" & templateResult & "'") -- DEBUG
-- display dialog "standaloneMode gesetzt auf: false" buttons {"OK"}
set templateResult to selectTemplate() of loadedScript
-- DEBUG
-- display dialog "templateResult: " & templateResult buttons {"OK"}
return templateResult return templateResult
on error errMsg on error errMsg
my writeDebug("FEHLER in runTemplateSelector: " & errMsg) display dialog "FEHLER: " & errMsg buttons {"OK"}
return "" return ""
end try end try
end runTemplateSelector 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." 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 if drChoice is "Abbrechen" then
my writeDebug("User hat Abbrechen geklickt") my writeDebug("User hat Abbrechen geklickt")
@@ -867,7 +878,7 @@ on run
set previewPath to my writeDryRunPreviewFile(toSend, theTo) set previewPath to my writeDryRunPreviewFile(toSend, theTo)
set dryRunText to my dryRunSummaryText(toSend, previewPath) 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 if dryRunChoice is "Liste im Finder zeigen" then
my showDryRunPreviewInFinder(previewPath) my showDryRunPreviewInFinder(previewPath)
end if end if
@@ -53,6 +53,7 @@ property requiredConfigKey : "BELEGE_ROOT_UUID="
property mainScriptName : "_belegversand.scpt" property mainScriptName : "_belegversand.scpt"
-- Versionsinformation für README und Hinweise. -- Versionsinformation für README und Hinweise.
property appVersion : "1.4" property appVersion : "1.4"
property basePath : "/Library/Application Scripts/com.devon-technologies.think/Menu/Belegversand"
-- Default-Werte für die Erstkonfiguration. -- Default-Werte für die Erstkonfiguration.
property defaultMailTo : "steuer@name.de" property defaultMailTo : "steuer@name.de"
property defaultSubjectPrefix : "Unterlagen" property defaultSubjectPrefix : "Unterlagen"
@@ -62,6 +63,69 @@ property defaultSentTagForDocs : "gesendet"
property defaultWriteDebugLog : "false" property defaultWriteDebugLog : "false"
property defaultShowReadme : "true" property defaultShowReadme : "true"
property defaultDryRunPreviewPath : "/tmp/DT-Belegversand-preview.txt" 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) runSiblingScript(scriptFileName)
-------------------------------- --------------------------------
@@ -73,7 +137,7 @@ Verwendung:
*) *)
on runSiblingScript(scriptFileName) on runSiblingScript(scriptFileName)
-- Absolute Basis-Path (Home + fest Installation) -- 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 set targetPath to basePath & "/Helpers/scripts/" & scriptFileName
try 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) on buildConfigText(mailToDefault, mailCcToDefault, subjectPrefix, zipPasswordDefault, logSentGroupName, belegeRootUUID, writeDebugLogValue, showReadmeValue, readmeUUID, mailBodyFolderName, mailBodyRecordName, sentTagForDocs, dryRunPreviewPath)
return "## Benutzer-Einstellungen - bitte individuell anpassen." & return & ¬ return "## Benutzer-Einstellungen - bitte individuell anpassen." & return & ¬
"## Eine Kurz-Doku findest du in der Datei README-Belegversand.md" & return & return & ¬ "## Eine Kurz-Doku findest du in der Datei README-Belegversand.md" & return & return & ¬
"APP_VERSION=" & appVersion & return & ¬
"MAIL_TO_DEFAULT=" & mailToDefault & return & ¬ "MAIL_TO_DEFAULT=" & mailToDefault & return & ¬
"MAIL_CC_TO_DEFAULT=" & mailCcToDefault & return & ¬ "MAIL_CC_TO_DEFAULT=" & mailCcToDefault & return & ¬
"MAIL_SUBJECT_PREFIX=" & subjectPrefix & return & ¬ "MAIL_SUBJECT_PREFIX=" & subjectPrefix & return & ¬
@@ -612,6 +677,18 @@ on run
set debugInfoText to "" set debugInfoText to ""
end if 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 & ¬ display dialog "Belegversand wurde eingerichtet." & return & return & ¬
"Datenbank-Wurzel: " & dbRootName & return & ¬ "Datenbank-Wurzel: " & dbRootName & return & ¬
"Belege-Gruppe: " & belegeRootName & return & ¬ "Belege-Gruppe: " & belegeRootName & return & ¬
+73 -61
View File
@@ -1,23 +1,22 @@
(* (*
show_mail_templates.scpt – Version 1.0 show_mail_templates.applescript – Version 1.4.1
Rolle dieses Scripts Rolle dieses Scripts
-------------------- --------------------
Dieses Helferlein listet alle verfügbaren Mail-Vorlagen aus /mail_vorlagen auf Listet alle verfügbaren Mail-Vorlagen aus /mail_vorlagen auf
und lässt den User eine davon via "choose from list" auswählen. und lässt den User eine davon auswählen.
Rückgabe: Property standaloneMode:
- Name der gewählten Vorlage-Datei - true (default): Script läuft alleine, User-freundlich
- Oder: leerer String, wenn User abbricht oder keine Vorlagen vorhanden - false: Aufgerufen von _belegversand, minimal intrusive
Verwendung:
Das Script wird vom Hauptscript _belegversand.scpt aufgerufen,
um dem User bei mehreren Mail-Vorlagen eine Auswahl zu bieten.
Behavior: Behavior:
- 0 Vorlagen: leer zurück - 0 Vorlagen (standalone): Dialog "mail_vorlagen ist leer"
- 1 Vorlage: direkt diese zurück (kein Dialog) - 0 Vorlagen (nicht standalone): leerer String
- >1 Vorlagen: choose from list Dialog - 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" tell application id "DNtp"
set sel to selection set sel to selection
@@ -28,11 +27,6 @@ tell application id "DNtp"
set selectedRecord to item 1 of sel set selectedRecord to item 1 of sel
end tell end tell
(*
getTopParentGroup(theRecord)
----------------------------
Ermittelt die DB-Wurzel relativ zu einem Record.
*)
on getTopParentGroup(theRecord) on getTopParentGroup(theRecord)
tell application id "DNtp" tell application id "DNtp"
set currentRecord to theRecord set currentRecord to theRecord
@@ -49,11 +43,6 @@ on getTopParentGroup(theRecord)
end tell end tell
end getTopParentGroup end getTopParentGroup
(*
findChildByName(parentRecord, childName)
----------------------------------------
Sucht ein Kind-Record nach Name.
*)
on findChildByName(parentRecord, childName) on findChildByName(parentRecord, childName)
tell application id "DNtp" tell application id "DNtp"
try try
@@ -67,49 +56,72 @@ on findChildByName(parentRecord, childName)
return missing value return missing value
end findChildByName end findChildByName
-- Hauptlogik on selectTemplate()
set dbRoot to getTopParentGroup(selectedRecord) -- Im Standalone-Modus: Erste DB nutzen statt Selection
set configGroup to findChildByName(dbRoot, "_config") 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
if configGroup is missing value then set dbRoot to getTopParentGroup(selectedRecord)
error "Keine _config-Gruppe gefunden." set configGroup to findChildByName(dbRoot, "_config")
end if if configGroup is missing value then
error "Keine _config-Gruppe gefunden."
end if
set mailTemplatesGroup to findChildByName(configGroup, "mail_vorlagen") set mailTemplatesGroup to findChildByName(configGroup, "mail_vorlagen")
if mailTemplatesGroup is missing value then
error "Keine mail_vorlagen-Gruppe gefunden."
end if
if mailTemplatesGroup is missing value then tell application id "DNtp"
error "Keine mail_vorlagen-Gruppe gefunden." set templateChildren to children of mailTemplatesGroup
end if end tell
-- Alle Dateien in mail_vorlagen auflisten set templateNames to {}
tell application id "DNtp" repeat with eachTemplate in templateChildren
set templateChildren to children of mailTemplatesGroup set templateName to (eachTemplate's name) & ""
end tell set end of templateNames to templateName
end repeat
if templateChildren is {} then -- EDGE CASE: 0 Vorlagen
-- Keine Vorlagen vorhanden → leerer String if templateNames is {} then
return "" if standaloneMode then
end if display dialog "Die DEVONthink-Gruppe /mail_vorlagen ist leer." buttons {"OK"} default button "OK"
end if
return ""
end if
-- Dateinamen sammeln -- EDGE CASE: 1 Vorlage
set templateNames to {} if (count of templateNames) is 1 then
repeat with eachTemplate in templateChildren if standaloneMode then
set templateName to (eachTemplate's name) & "" display dialog "Folgende Mail-Vorlage gefunden:" & return & return & (item 1 of templateNames) buttons {"OK"} default button "OK"
set end of templateNames to templateName end if
end repeat return item 1 of templateNames
end if
-- Wenn nur eine Vorlage: diese direkt zurückgeben (kein Dialog) -- NORMAL: >1 Vorlagen
if (count of templateNames) is 1 then set chosenTemplate to choose from list templateNames with title "Mail-Vorlage(n)..." with prompt "Folgende Vorlagen gefunden:"
return item 1 of templateNames if chosenTemplate is false then
end if return ""
else
return item 1 of chosenTemplate
end if
end selectTemplate
-- Wenn mehrere Vorlagen: User wählen lassen -- Wenn standalone aufgerufen
set chosenTemplate to choose from list templateNames with title "Mail-Vorlage(n)..." with prompt "Folgende Vorlagen gefunden:" selectTemplate()
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
+8 -3
View File
@@ -28,6 +28,12 @@ property setupScriptName : "_belegversand_setup.scpt"
property configGroupName : "_config" property configGroupName : "_config"
-- Name der eigentlichen Konfigurationsdatei in DEVONthink. -- Name der eigentlichen Konfigurationsdatei in DEVONthink.
property configRecordName : "belegversand.conf" 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) runSiblingScript(scriptFileName)
-------------------------------- --------------------------------
@@ -36,7 +42,7 @@ Parameter:
- scriptFileName : Dateiname des aufzurufenden Scripts, z. B. - scriptFileName : Dateiname des aufzurufenden Scripts, z. B.
"_belegversand_setup.scpt" "_belegversand_setup.scpt"
Ablauf: 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 - daran den Unterordner "Helpers/scripts" und den Dateinamen anhängen
- prüfen, ob die Scriptdatei existiert - prüfen, ob die Scriptdatei existiert
- Script laden - Script laden
@@ -50,8 +56,7 @@ Der absolute Pfad ist invariant und unabhängig vom Speicherort dieses Scripts.
*) *)
on runSiblingScript(scriptFileName) on runSiblingScript(scriptFileName)
-- Absolute Basis-Path (Home + fest Installation) -- 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 (do shell script "echo ~") & "/" & basePath & "/Helpers/scripts/" & scriptFileName
set targetPath to basePath & "/Helpers/scripts/" & scriptFileName
try try
set targetAlias to POSIX file targetPath as alias set targetAlias to POSIX file targetPath as alias