Warning
Please note:
Update
This version adds/changes/requires:
- ADD field to change existing tags
- ADD: Integrates with AI to rename documents
- REQUIRES: AI which handles the renaming - I prefer local MstyStudio which includes Ollama as backend + phi4 as model for that, but Ollama standallone, LM Studio etc. should be fine, too.
- ADD: Presets which sets fields within the document DYNAMICALLY - but there’s a price to pay: Each run within Script Debugger of the script requires a recompile
- ADD: Re-evaluate rules (Redo) after changing them during runtime
- ADD: Delete file from dialogue
- ADD: Databases are filled dynamically from databases opened in DT
- CHANGES: Total refactoring of
tellapplicationid "DNtp". I wrapped Dialog Toolkit Plus with that code. This breaks “Dialog Toolkit Plus” with a “Main Thread warning”. Now I only wrap code which requires DT
AI renaming
It takes about 10 s to 20 s per file on a M2 Mac with 15.x to rename a file. Most times the result is fine. I use the renaming as part of my input pipeline to change file names generated by my Epson scanner (scan-.pdf). For other documents I got by mail, I added the button in my review process.
I think about moving to two tier approach:
- LLM generate unstructured output containing the name
- SLM generate structured output from the LLM output
I read some blogs mentioning an improvement in speed.
More information
This code is based on examples found here: Change elements dynamically using Shane's Dialog Toolkit? - #11 by t.spoon - AppleScript | Mac OS X - MacScripter plus own research within the Dialog Toolkit Plus code base.
The code allows a developer to use a dropdown to change values of other fields within the dialog. I use it to configure presets. The presets are defined within a property as array of dictionaries. The ¬ makes it possible to break up the long string - <opt>+L.
property dialogPresets : {¬
{presetTitle:"Global: No preset", yearlyLocation:true, basePath:"", databaseName:"", addTags:{}, companyName:""}, ¬
{presetTitle:"Global: No rule", yearlyLocation:false, basePath:"/_Review/.NORULE", databaseName:"Inbox", addTags:{}, companyName:""}, ¬
{presetTitle:"Global: Handbücher", yearlyLocation:false, basePath:"/Handbuecher", databaseName:"knowledge", addTags:{"handbuch"}, companyName:""}, ¬
{presetTitle:"Global: Rente", yearlyLocation:true, basePath:"/Rente", databaseName:"business", addTags:{"rente"}, companyName:""}, ¬
{presetTitle:"Global: Projekte", yearlyLocation:false, basePath:"/_Projekte/" & currentYear & "/CHANGEME", databaseName:"personal", addTags:{"projekt"}, companyName:""}, ¬
{presetTitle:"Global: Sonstiges-Behoerden", yearlyLocation:true, basePath:"/Vertraege-und-Rechnungen/_Sonstiges-Behoerden", databaseName:"business", addTags:{"verwaltung", "behoerden"}, companyName:""}, ¬
{presetTitle:"Global: Sostiges-Gesundheit", yearlyLocation:true, basePath:"/Vertraege-und-Rechnungen/_Sonstiges-Gesundheit", databaseName:"business", addTags:{"health", "gesundheit"}, companyName:""}, ¬
{presetTitle:"Global: Sonstiges-Kaufbelege", yearlyLocation:true, basePath:"/Vertraege-und-Rechnungen/_Sonstiges-Kaufbelege", databaseName:"business", addTags:{"rechnungen", "invoice"}, companyName:""}, ¬
{presetTitle:"Global: Tipps", yearlyLocation:false, basePath:"/Tipps/Assets", databaseName:"knowledge", addTags:{"tipp"}, companyName:""}, ¬
{presetTitle:"Global: Urlaub", yearlyLocation:true, basePath:"/_Urlaub", databaseName:"personal", addTags:{"urlaub", "holidays"}, companyName:""}, ¬
{presetTitle:"Global: Vorlagen", yearlyLocation:false, basePath:"/_Neu", databaseName:"templates", addTags:{"template"}, companyName:""} ¬
}
It requires properties for each supported field defined.
on updateOtherFields:sender
try
-- set index of selected dropdown item
local selectedPresetIndex
set selectedPresetIndex to (my presetsPopup's indexOfSelectedItem() as integer) + 1
set selectedPreset to item selectedPresetIndex of dialogPresets
-- get values for selected dropdown
local selectedCompanyName, selectedLocation, selectedTags, joinedTags, selectedDatabase, selectedYearlyLocation
set selectedCompanyName to (companyName of selectedPreset as text)
set selectedLocation to (basePath of selectedPreset as text)
local selectedTags
set selectedTags to (addTags of selectedPreset)
set joinedTags to (join strings selectedTags using delimiter ",")
set selectedDatabase to (databaseName of selectedPreset as text)
set selectedYearlyLocation to (yearlyLocation of selectedPreset as boolean)
-- set values
-- https://www.macscripter.net/t/change-elements-dynamically-using-shanes-dialog-toolkit/70409/11
my (companyField's setStringValue:selectedCompanyName)
my (locationPathField's setStringValue:selectedLocation)
my (tagsField's setStringValue:joinedTags)
my (databaseField's setStringValue:selectedDatabase)
my (yearlyLocationCheckbox's setState:selectedYearlyLocation)
on error errMsg number errNum partial result partialError
set AppleScript's text item delimiters to {return}
-- An unknown error occurred. Resignal, so the caller
-- can handle it, or AppleScript can display the number.
display alert errMsg & ("Error number: ") & errNum & return & (partialError as text)
error errMsg & ("Error number: ") & errNum & return & (partialError as text)
end try
end updateOtherFields:
