# \[SOLVED\] Need a bit of help with a simple (?) AI task - file renaming

**URL:** <https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380>\
**Category:** Automation\
**Created:** [May 3, 2025, 11:15am UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380 "2025-05-03T11:15:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![uimike](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/uimike/32/37894_2.png) [@uimike](https://discourse.devontechnologies.com/u/uimike)\
**Post date:** [May 3, 2025, 11:15am UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/1 "2025-05-03T11:15:52Z")

</div>

Hi, I am slowly learning how to use the AI features, and could use some help with a (?) task…  
I OCR’d a number of screen captures, and it would be great if I can rename the records to exactly what is in the 1st line. - check the image attached - how to go about it? Thanks!

I’d like the filename to read “1976 Dvukralove Wildlife Park”  
(upload://55SJvECOFhoEotNkOiHCF1lzPYz.pdf) (184.4 KB)

 ![Screenshot 2025-05-03 at 12.45.07 PM](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/e/9/e9b6518c7873343e30876069353d160089ce7064.png)

---

<div class="post-metadata">

**Author:** ![chrillek](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/chrillek/32/29340_2.png) [@chrillek](https://discourse.devontechnologies.com/u/chrillek)\
**Post date:** [May 3, 2025, 11:41am UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/2 "2025-05-03T11:41:37Z")

</div>

Please post screenshots directly in your text.

I think AI is not needed for that kind of task. Something like

- scan text for regular expression ‘^(.\*)$’
- Set name to ‘\1’

In a smart rule should be enough.

---

<div class="post-metadata">

**Author:** ![uimike](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/uimike/32/37894_2.png) [@uimike](https://discourse.devontechnologies.com/u/uimike)\
**Post date:** [May 3, 2025, 11:46am UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/3 "2025-05-03T11:46:07Z")

</div>

Did it, thanks Christian - will try and use your suggestion, thanks!

EDIT: hm, doesn’t seem to be working?  
This is the batch action I created, when I apply it, the filename does not change.

 ![Screenshot 2025-05-03 at 12.52.59 PM](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/b/b/bb71734e2ecc1d960ad60f9d70aa03cce777a077.png)

---

<div class="post-metadata">

**Author:** ![chrillek](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/chrillek/32/29340_2.png) [@chrillek](https://discourse.devontechnologies.com/u/chrillek)\
**Post date:** [May 3, 2025, 11:53am UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/4 "2025-05-03T11:53:30Z")

</div>

Since the screenshot must come from somewhere, there might also exist a possibility to ask the original app for the name of the group/folder/whatever it uses

---

<div class="post-metadata">

**Author:** ![uimike](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/uimike/32/37894_2.png) [@uimike](https://discourse.devontechnologies.com/u/uimike)\
**Post date:** [May 3, 2025, 11:55am UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/5 "2025-05-03T11:55:04Z")

</div>

I think probably not here, Christian, as it is just an Apple capture - if I understand what you are saying.

---

<div class="post-metadata">

**Author:** ![uimike](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/uimike/32/37894_2.png) [@uimike](https://discourse.devontechnologies.com/u/uimike)\
**Post date:** [May 3, 2025, 12:09pm UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/6 "2025-05-03T12:09:50Z")

</div>

Using ScriptDebugger Explorer - I can see the following as the ‘plain text’ property of the record:

“1976 Dvurkralove Wildlife Park\n3. November WM: None Design: J. Baláz Perforation: 113/4 x 111/4\nI\n-\ny (l\nCáiMevenókí}\nOOh\nCuddlogngf...”

The first bit, up to the first new line \n is what I want - I think I could write an applescript for that (1), but using regex is fun if I can 🙂

(1) changing the delimiters to “\n” maybe

---

<div class="post-metadata">

**Author:** ![chrillek](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/chrillek/32/29340_2.png) [@chrillek](https://discourse.devontechnologies.com/u/chrillek)\
**Post date:** [May 3, 2025, 12:14pm UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/7 "2025-05-03T12:14:45Z")

</div>

AS is overkill for that case, as is AI. And if it’s just the screenshot of a folder contents, one could perhaps set up something to capture the folder name?  
I mean, if you’re going through your complete collection, automation might be helpful …

---

<div class="post-metadata">

**Author:** ![uimike](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/uimike/32/37894_2.png) [@uimike](https://discourse.devontechnologies.com/u/uimike)\
**Post date:** [May 3, 2025, 12:18pm UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/8 "2025-05-03T12:18:08Z")

</div>

Ah, no - it will be hundreds of screenshots, taken from online stamp catalogs. As it happens, I adjust the screenshot selection area to start at the stamp set title. But there will be many, many, hence the usefulness of some automation.

Can you think of a js to capture the plain text until the first return / new line?

---

<div class="post-metadata">

**Author:** ![chrillek](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/chrillek/32/29340_2.png) [@chrillek](https://discourse.devontechnologies.com/u/chrillek)\
**Post date:** [May 3, 2025, 12:50pm UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/9 "2025-05-03T12:50:52Z")

</div>

> [@uimike](#):
>
> Can you think of a js to capture the plain text until the first return / new line?

Easy:

```javascript
function performsmartrule(records) {
  records.forEach(r => {
    const txt = r.plainText();
    const newName = txt.split('\n')[0];
    r.name = newName;
  })
}

```

It gets the plain text attribute, splits it at newlines, which gives an array. It then takes the first element of this array (aka the first line of text) and sets that as the name.

I didn’t try that at all, though. Just wrote it down. So test it on copies of your data first!

---

<div class="post-metadata">

**Author:** ![uimike](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/uimike/32/37894_2.png) [@uimike](https://discourse.devontechnologies.com/u/uimike)\
**Post date:** [May 3, 2025, 2:50pm UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/10 "2025-05-03T14:50:01Z")

</div>

Bingo!! thank you so much Christian!!

 ![Screenshot 2025-05-03 at 12.52.59 PM](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/b/b/bb71734e2ecc1d960ad60f9d70aa03cce777a077.png)  
 ![Screenshot 2025-05-03 at 3.49.09 PM](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/e/d/ed98b7fa50ef88fd71eb716fa027efbb63dc9bcc.png)

---

<div class="post-metadata">

**Author:** ![chrillek](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/chrillek/32/29340_2.png) [@chrillek](https://discourse.devontechnologies.com/u/chrillek)\
**Post date:** [May 3, 2025, 2:56pm UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/11 "2025-05-03T14:56:57Z")

</div>

Let’s hope that the text recognition is reliable…

---

<div class="post-metadata">

**Author:** ![uimike](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/uimike/32/37894_2.png) [@uimike](https://discourse.devontechnologies.com/u/uimike)\
**Post date:** [May 3, 2025, 3:23pm UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/12 "2025-05-03T15:23:27Z")

</div>

It’s been flawless!!  
Already processed 300+ screenshots

Now a curiosity: for screenshots from some stamp catalogs, the stamp set title cannot be cleanly isolated, just because of the web page layout.

In this case, I have been going to the screenshot and cropping the original png - so as to leave the stamp title as first line in the image, before running the OCR.

The default app for png is Preview. But Preview has an annoyance. After cropping, it wants to save a copy somewhere, and invokes the Save Dialog. Of course, you should not save to the internal DEVONthink file where the original lives.

So I switched to opening the pngs with Acorn - and Acorn does replace the original file cleanly.  
Then OCR, run chrillek’s script, and done.

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [May 3, 2025, 4:00pm UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/13 "2025-05-03T16:00:13Z")

</div>

> [@uimike](#):
>
> The default app for png is Preview. But Preview has an annoyance. After cropping, it wants to save a copy somewhere, and invokes the Save Dialog. Of course, you should not save to the internal DEVONthink file where the original lives.

The documents are in the Global Inbox?

---

<div class="post-metadata">

**Author:** ![uimike](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/uimike/32/37894_2.png) [@uimike](https://discourse.devontechnologies.com/u/uimike)\
**Post date:** [May 3, 2025, 4:11pm UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/14 "2025-05-03T16:11:35Z")

</div>

yep.

Ah, I see - it works ok when inside some database. Got it - thanks Jim!

(and, sure, I understand why a record in the Global Inbox cannot and should not itself be modified)

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [May 3, 2025, 8:35pm UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/15 "2025-05-03T20:35:26Z")

</div>

> [@uimike](#):
>
> (and, sure, I understand why a record in the Global Inbox cannot and should not itself be modified)

It’s actually an issue specific to Preview and items in the user Library. It harkens back to the same time they made the Library a hidden directory.

---

<div class="post-metadata">

**Author:** ![uimike](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/uimike/32/37894_2.png) [@uimike](https://discourse.devontechnologies.com/u/uimike)\
**Post date:** [May 3, 2025, 11:34pm UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/16 "2025-05-03T23:34:05Z")

</div>

Got it - thanks Jim

---

<div class="post-metadata">

**Author:** ![troejgaard](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@troejgaard](https://discourse.devontechnologies.com/u/troejgaard)\
**Post date:** [May 4, 2025, 1:05am UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/17 "2025-05-04T01:05:43Z")

</div>

> [@uimike](#):
>
> using regex is fun if I can 🙂

After a little testing, I’m pretty sure the `m` flag is not enabled by default. In that case `^(.*)$` is too greedy, as `^` and `$` don’t refer to the start/end of a line, but the input as a whole.

Instead, `^(.*)\n` works. (Everything from start until a newline)

Or `(?m)^(.*)$`. It’s not necessary here, but it’s nice to be aware of the option. (Only the first match is captured).

---

<div class="post-metadata">

**Author:** ![chrillek](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/chrillek/32/29340_2.png) [@chrillek](https://discourse.devontechnologies.com/u/chrillek)\
**Post date:** [May 4, 2025, 2:39pm UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/18 "2025-05-04T14:39:55Z")

</div>

Interesting. I tried `^(.*)$` on a PDF with text and it gave me _nothing_ (quite the opposite of “too greedy” 😉 )  
Then, `^(.*)\n` gave me the first line of the PDF (as you said).

According to the [ICU regex documentation](https://unicode-org.github.io/icu/userguide/strings/regexp.html), `$` should match `\000a`, which is the character representing `\n`. OTOH, they describe the effect of the `m` flag exactly as you do (and [regex101.com](http://regex101.com) shows the same behavior).

So, `^(.*)$` works for the OP, but it shouldn’t. Well.

---

<div class="post-metadata">

**Author:** ![uimike](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/uimike/32/37894_2.png) [@uimike](https://discourse.devontechnologies.com/u/uimike)\
**Post date:** [May 4, 2025, 2:54pm UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/19 "2025-05-04T14:54:04Z")

</div>

Actually, that regex did not work for me, gave me exactly what it gives you - nada.  
But, as your js was so prefectly suited for my needs, I am happy using it in a batch action 🙂

I’ll play with the regex just for fun

---

<div class="post-metadata">

**Author:** ![uimike](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/uimike/32/37894_2.png) [@uimike](https://discourse.devontechnologies.com/u/uimike)\
**Post date:** [May 4, 2025, 2:55pm UTC](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380/20 "2025-05-04T14:55:08Z")

</div>

thanks troej, I’ll play with that (chrillek’s js is already working perfectly for me, but hey, why stop when the problem is solved 😉

[Next page](https://discourse.devontechnologies.com/t/solved-need-a-bit-of-help-with-a-simple-ai-task-file-renaming/83380.md?page=2)
