Zum Inhalt

📂 DEVONthink API

Typ: AppleScript + URL Scheme
Auth: Lokal (keine API-Keys)
Status: ✅ Verfügbar (macOS only)


Übersicht

DEVONthink ist ein Dokumentenmanagementsystem für macOS mit: - Intelligente Dokumentenablage und Suche - AI-gestützte Klassifizierung (DT4 mit OpenAI/Anthropic) - OCR und PDF-Verarbeitung - Sync über CloudKit, WebDAV, Bonjour

Use Cases für ContractPlattform: - Vertragsablage und Archivierung - Volltext-Suche in PDFs/Scans - AI-Zusammenfassungen von Dokumenten - Automatische Kategorisierung


Zugangsoptionen

Methode Beschreibung Status
AppleScript Native macOS Automation ✅ Vollzugriff
URL Scheme x-devonthink:// Links ✅ Verfügbar
JavaScript (JXA) JavaScript for Automation ✅ Verfügbar
REST API Nicht verfügbar

AppleScript Endpoints

Aktion Beschreibung Cache TTL
create record Dokument erstellen -
search Volltextsuche 5 min
get record Dokument abrufen 1 min
get children Ordnerinhalt 1 min
delete record Dokument löschen -
move record Verschieben -
replicate Replizieren -
duplicate Duplizieren -
get databases Datenbanken auflisten 1h
get groups Gruppen/Ordner 5 min

AppleScript Beispiele

Dokument erstellen

tell application id "DNtp"
    set theDatabase to open database "/Users/user/Documents/Contracts.dtBase2"
    set theGroup to get record at "/Verträge/2025" in theDatabase

    set newDoc to create record with {
        name: "Mietvertrag_Müller_2025.pdf",
        type: pdf document,
        path: "/tmp/vertrag.pdf"
    } in theGroup

    -- Tags hinzufügen
    set tags of newDoc to {"Mietvertrag", "2025", "Müller"}

    -- Custom Metadata
    set custom meta data of newDoc to {|contractId|:"CNT-2025-001", |tenant|:"Max Müller"}
end tell

Volltextsuche

tell application id "DNtp"
    set searchResults to search "Mietvertrag Müller" in database "Contracts"

    repeat with doc in searchResults
        log (name of doc) & " - Score: " & (score of doc)
    end repeat
end tell

AI-Zusammenfassung (DT4)

tell application id "DNtp"
    set theDoc to get record at "/Verträge/Mietvertrag.pdf" in database "Contracts"

    -- AI Chat mit Dokument-Kontext
    set summary to summarize record theDoc

    -- Oder mit Custom Prompt
    set result to chat with theDoc prompt "Fasse die wichtigsten Vertragspunkte zusammen"
end tell

JavaScript (JXA) Beispiel

// DEVONthink JXA Bridge
const DEVONthink = Application('DEVONthink 3');
DEVONthink.includeStandardAdditions = true;

// Datenbank öffnen
const db = DEVONthink.openDatabase('/Users/user/Contracts.dtBase2');

// Dokument suchen
const results = DEVONthink.search('Mietvertrag 2025', { in: db });

results.forEach(doc => {
    console.log(`${doc.name()} - ${doc.path()}`);
});

// Neues Dokument erstellen
const group = DEVONthink.getRecordAt('/Verträge/2025', { in: db });
const newDoc = DEVONthink.createRecordWith({
    name: 'Neuer Vertrag.pdf',
    type: 'pdf document',
    path: '/tmp/vertrag.pdf'
}, { in: group });

// Tags setzen
newDoc.tags = ['Mietvertrag', '2025'];

URL Scheme

# Dokument öffnen (UUID)
open "x-devonthink://item?uuid=ABC123-DEF456"

# Suche ausführen
open "x-devonthink://search?query=Mietvertrag%202025"

# Dokument erstellen
open "x-devonthink://createDocument?title=Neuer%20Vertrag&text=Inhalt"

# Datenbank öffnen
open "x-devonthink://openDatabase?path=/Users/user/Contracts.dtBase2"

Node.js Bridge (via osascript)

import { exec } from 'child_process';
import { promisify } from 'util';

const execAsync = promisify(exec);

interface DEVONthinkDocument {
  uuid: string;
  name: string;
  path: string;
  tags: string[];
  score?: number;
}

class DEVONthinkBridge {
  private database: string;

  constructor(databasePath: string) {
    this.database = databasePath;
  }

  async search(query: string): Promise<DEVONthinkDocument[]> {
    const script = `
      tell application id "DNtp"
        set db to open database "${this.database}"
        set results to search "${query}" in db
        set output to ""
        repeat with doc in results
          set output to output & (uuid of doc) & "||" & (name of doc) & "||" & (path of doc) & "\\n"
        end repeat
        return output
      end tell
    `;

    const { stdout } = await execAsync(`osascript -e '${script}'`);
    return this.parseResults(stdout);
  }

  async createDocument(name: string, content: string, group: string, tags: string[]): Promise<string> {
    const tagsStr = tags.map(t => `"${t}"`).join(', ');
    const script = `
      tell application id "DNtp"
        set db to open database "${this.database}"
        set grp to get record at "${group}" in db
        set newDoc to create record with {name:"${name}", type:txt, plain text:"${content}"} in grp
        set tags of newDoc to {${tagsStr}}
        return uuid of newDoc
      end tell
    `;

    const { stdout } = await execAsync(`osascript -e '${script}'`);
    return stdout.trim();
  }

  async importFile(filePath: string, group: string, tags: string[]): Promise<string> {
    const tagsStr = tags.map(t => `"${t}"`).join(', ');
    const script = `
      tell application id "DNtp"
        set db to open database "${this.database}"
        set grp to get record at "${group}" in db
        set newDoc to import "${filePath}" to grp
        set tags of newDoc to {${tagsStr}}
        return uuid of newDoc
      end tell
    `;

    const { stdout } = await execAsync(`osascript -e '${script}'`);
    return stdout.trim();
  }

  private parseResults(output: string): DEVONthinkDocument[] {
    return output.trim().split('\n')
      .filter(line => line.includes('||'))
      .map(line => {
        const [uuid, name, path] = line.split('||');
        return { uuid, name, path, tags: [] };
      });
  }
}

// Usage
const dt = new DEVONthinkBridge('/Users/user/Documents/Contracts.dtBase2');

// Suche
const results = await dt.search('Mietvertrag Müller');
console.log(results);

// Import
const uuid = await dt.importFile('/tmp/vertrag.pdf', '/Verträge/2025', ['Mietvertrag', '2025']);
console.log(`Imported: ${uuid}`);

AI Integration (DT4)

DEVONthink 4 unterstützt AI-APIs:

Provider Modelle Status
OpenAI GPT-4, GPT-4o
Anthropic Claude 3.5
Ollama Llama, Mistral ✅ (lokal)
LM Studio Diverse ✅ (lokal)
-- AI-Zusammenfassung
tell application id "DNtp"
    set doc to get record at "/Verträge/Mietvertrag.pdf"
    set summary to summarize record doc
end tell

-- Custom AI Chat
tell application id "DNtp"
    set doc to get record at "/Verträge/Mietvertrag.pdf"
    set response to chat with doc prompt "Wann endet der Vertrag?"
end tell

Umgebungsvariablen

# DEVONthink Database Path
DEVONTHINK_DATABASE="/Users/user/Documents/Contracts.dtBase2"

# Default Import Group
DEVONTHINK_IMPORT_GROUP="/Inbox"

# AI Provider (für DT4)
DEVONTHINK_AI_PROVIDER="openai"  # openai | anthropic | ollama

Limitierungen

Aspekt Limitation
Plattform macOS only
API Kein REST, nur AppleScript
Remote Kein Remote-Zugriff (nur Sync)
Linux/Windows ❌ Nicht verfügbar

Sync-Optionen

Methode Beschreibung
CloudKit iCloud Sync
WebDAV Eigener Server
Bonjour LAN Sync
Dropbox Encrypted Sync Store

macOS only • AppleScript/JXA • AI-ready (DT4)