NSThread doesn’t understand the “isMainThread” message.
I’m a bit lost fixing the error above. ![]()
I searched the web and found some threads - e.g. Dialog Toolkit Plus 1.1.3 'NSThread doesn't understand the "isMainThread" message.' - AppleScript | Mac OS X - MacScripter - about it, but none really helped. It happens from time to time, but at some times it’s quite persistent. Working on it for several months now, I really want to get rid of it. Every time, I think it’s fixed, it came up again after some minor changes to the script.![]()
I run the script from the external scripts menu.
The scripts expect to be stored here:
scripts.zip (169.2 KB)
-- script
~/Library/Scripts/Applications/DEVONthink/_Review documents.scpt
-- libraries
~/Library/Script Libraries/fx-devonthink-base.scpt
~/Library/Script Libraries/fx-devonthink-ai.scpt
~/Library/Script Libraries/fx-review-documents-rules.scpt
-- script used as library
~/Library/Scripts/Applications/DEVONthink/_Rename record with AI.scpt
At some point I thought:
- Wrapping
tell […] endwas the problem - The length of the _Review-script was the problem
- Maybe loading external scripts make AppleScript spawn a thread
What really made it persistent: Load an external script/library in a property.
Loading external scripts with the following code, works around caching of AppleScripts which is quite handy. This allows to change the rules I use without closing/opening DT. So this is something I really hesitate to get rid of.
on getMetadataForRecord(theRecord, thisYear, isDev)
local scriptName
set scriptName to "fx-review-documents-rules"
local scriptPath
set scriptPath to (system attribute "HOME") & globalLibrariesPath & scriptName & ".scpt"
local scriptHandler
set scriptHandler to load script (POSIX file scriptPath as alias)
-- use rules to get metadata about file
-- default is missing value if no rule matches
local recordMetadata
set recordMetadata to scriptHandler's getMetadataForRecord(theRecord, thisYear, isDev)
return recordMetadata
end getMetadataForRecord
Anyway, I will try to build a script without any of MY external dependencies and will see what happens. Better a cached script, than a non-functional one.
If one tries the dialog with the AI renaming:
- Make sure you’ve got LM Studio set up
- Get mistral-small as model (Thanks @BLUEFROG, best results so far)
- Setup
templatesdb withMeine Promptsgroup at top - Add prompt
Meine Prompts >_Rename record with AI.scpt.txt - OR: change the scripts accordingly
Content of prompt:
You are a document renaming AI. Extract content and generate standardized German filenames in JSON format only.
## Analysis Steps:
1. **Extract Date** (priority order):
- Official document date → Receipt date → RECORD_CREATED_DATE → CURRENT_DATE
2. **Identify**:
- Entity: Organization/sender name
- Document type: Invoice, contract, receipt, etc.
- Key details: Reference numbers, descriptions
3. **Format Components**:
- Use PascalCase, no spaces/special characters
- Max lengths: Entity (25), Description (30)
- Translate non-German text to German
## Output JSON Only:
```json
{
\"new_filename\": \"string\",
\"new_date\": \"YYYY-MM-DD\",
\"topic\": \"string\",
\"subtopic\": \"string\",
\"descriptor\": \"string\",
\"doc_type\": \"enum(rechnung, vertrag, quittung, versicherungspolice, mietvertrag, garantieschein, steuerbescheid, kontoauszug, kreditvertrag, kostenvoranschlag, bescheinigung, gehaltsabrechnung, vollmacht, mahnung, lieferschein, bestellung, angebot, rechtsanwalt_schreiben, gerichtsbeschluss, urkunde, amtsbescheid, anderes_dokument)\"
}
```
**Filename format:** [topic]-[subtopic]-[descriptor]-[doc_type]
**Character rules:** A-Z, a-z, 0-9, hyphens, underscores only. No explanation text.
