My pleasure
Setting the Usage option in Settings > AI > Chat to Cheapest is one possibility to reduce costs. Another one is to select a dedicated engine/model for the Chat - Query/Continue if… actions (see pop-up menu to the left of the input field, just like in the chat assistant).
E.g. for simple automations like this one even local models like Gemma 3 are frequently sufficient.
Thank you… I will need to figure out alternatives blew apart that $10 credit I put on yesterday. Tried to make the script @BLUEFROG provided, but I couldn’t make it work for me. I have downloaded the local models… but this is going to take some time, all a little over my head, and yet it seemed like a simple project… rename based on title, pub date and author
What was the issue?
It just doesn’t run I tried with Chat GPT and Claude (bought credits
) but didn’t work – I know it is something I am doing, not your script… but it just ain’t playing ball.
For ChatGPT (used chat to help tweak the script) – I also tried GPT-4o (Mini)
in the script. Maybe it’s because I’m now all cross-eyed that I’m not seeing straight, but I haven’t had a successful run yet using tany version of the script.
tell application id "DNtp"
-- Get the first 25 paragraphs of the selected record
set limitedText to (paragraphs 1 thru 25 of (get plain text of (selected record 1))) as string
-- Define the prompt
set thePrompt to "Rename this ebook using the following content: " & limitedText & "
Use only the book’s short title, the 4-digit publication year, and the author's last name. If the book was translated, add “-trans-” and the translator’s last name.
Return ONLY the filename. Do NOT include quotes, explanation, extra words, or punctuation of any kind.
Format exactly like this: lowercase-words-separated-by-dashes ending in -yyyy-author[-trans-translator]
Examples:
changing-direction-2006-dekoven
poetics-1996-aristotle-trans-heath"
-- Query ChatGPT (GPT-4o)
set responseText to get chat response for message thePrompt engine ChatGPT model "GPT-4o"
-- Optional: Show result
display dialog "Suggested filename: " & responseText buttons {"OK"} default button 1
end tell
The original ‘Claude version’ of the script lives here alongside my adapted one for ChatGPT:
I have now also downloaded Ollama and LM Studio as per @cgrunenberg suggestion – if I can make this work (script in combination with a local model) it seems a more financially savvy move considering I am just renaming pdfs.
Any point in the right direction would be wonderful
I am only running Ollama, not LM Studio, GPT4All, etc. using the gemma3:4b
model (8GB RAM Mac at the moment, so it’s not going to be running larger models than that). It gave similar results to Claude’s suggestions but always remember, AI generally is not producing static replies.
tell application id "DNtp"
set sel to (selected record 1)
set limitedText to (paragraphs 1 thru 10 of (get plain text of sel))
show progress indicator "Parsing for a rename…" steps -1
set thePrompt to "Rename this ebook using " & limitedText & " If the book was translated, add “-trans-” and the translator’s last name. Format the filename exactly like this: all lowercase words separated by dashes , ending in -yyyy-author[-trans-translator]. Do not return any explanation, commentary, or punctuation, only the filename. Examples: changing-direction-2006-dekoven or poetics-1996-aristotle-trans-heath"
set res to get chat response for message thePrompt engine Ollama model "gemma3:4b" without tool calls
set comment of sel to (comment of sel & linefeed & "Original name: " & (name without extension of sel))
set name of sel to res
step progress indicator "Renamed"
delay 1
hide progress indicator
end tell
It has a little visual feedback using the Activity pane.
It is now 2:25am and I am going to sleep.
you might also check out another route: there are some dedicated apps, like PDFZone, allowing for content-based renaming of PDFs.
– drawback: this (mostly) relies on data being positioned/present in a stable graphical pattern.
so, only works for some use cases.
In case of such patterns even a smart rule using the action Scan Text might be sufficient.
I’m wondering why you do not use the metadata that should be provided in the PDF itself?
When I import a PDF e-book, I get the title and the author in DT’s metadata in the right sidebar’s inspector. The creation date … unfortunately, DT does not take that from the PDF’s creation date, but a fairly short script can retrieve it. There would be a hidden preference to enable that, but I can’t find it – @bluefrog?
There’s a hidden preference UseDocumentDates
. Setting that to true
or 1
will use the PDF’s creation date as DT’s creation date, too. So, everything you need for your renaming with a smart rule is in place, no scripting needed.
So, as @cgrunenberg hinted at, your problem could probably easily be solved with a smart rule, including a small script. AI is not the answer to everything, sometimes there are simpler and cheaper approaches.
So, it is even easier to perform the name change without resorting to talking to an AI.
Depending on the requirements, this indeed could be true.
Thank you Bluefrog and everyone else who has so kindly contributed their time to trying to help me. Apologies for the delay getting back, work got busy and then Easter.
I’m going to have to take a step back on this as it is all a little too big and overwhelming. In the interim, I downloaded an app from the Apple Store called Sortie, it uses Ollama locally and you can easily rename or sort files using a prompt. It is really easy to use… from a point of love for DEVONthink, it might be an idea to try make the AI features a little less technical for us ‘norms’ or maybe that is ‘technically challenged’ for me?
I woud love to ba able to easily and convieniently use AI in DEVONthink, but it would need to be a little easier. (I’m still trying to get that script running you provided… copy pasted into script editor, saved in the script folder and ran script on a document… but nothing…)
Anyway, I do appreaciate you all! Thank you again for the help
Well, if you ran my script as-is you’d need to look at the Annotations & Reminders inspector as it’s writing to the Finder Comments.