(solved) Batch-rename/script-rename by custom metadata field - howto?


a beginner needs a little help, please.

I’d like to have tons of imported PDF documents (from other ecm-applications producing horrible file names) - in one group - renamed by custom metadata fields I added to database.

As I understand there are two options of files in devonthink databases, the ones that are indexed only and the ones that are imported. As a newbie getting used to I’m using imported files in the beginning, to setup my ecm environment and synchronize one database via icloud.

Coming from enterprise ecm applications, metadata fields are absolutely relevant - I’m happy being able to setup custom metadata-fields within devonthink.

Filenames are normally less relevant for me as they “interfere” only within devonthink desktop application, but in the To-Go-app they disrupt my workflow (as I do see filenames in document list) so I need them being renamed for better usage. If possible:

Filename/name of pdf should be sth. like


if that is possible - I must admit it might be possible that sometimes metadata fields are not filled correctly.

I found out there might be a batch rename action when I select more than one document, but I do have trouble setting up metadata-fields into UI (I wonder if that is really possible or just UI misunderstanding by myself). I also found some of your scripts, but nothing that matches my needs or can be adapted to my needs as I’m absolutely no genius in programming or scripting.

So can you help out please?

Thank you!

I must admit it might be possible that sometimes metadata fields are not filled correctly.

And what is the fallback in these scenarios?

PS: I don’t know the length of the custom metadata you’re referring to but here’s something to consider:


I’d like to have it ignored in this case so script won’t crash if that is possible.

Yes, one my fields will have up to 20 chars (and this for sure makes filename mucg longer). Your article sounds good to me - I think (now) there’s much room to optimize.

Here’s a simple example merely using placeholders in a smart rule…

And the resulting file…


This will not error if the metadata field is empty. You’d just end up with two underscores. This may or may not be acceptable. I personally have no issue with it as it could be useful in later automation since the null space between the two underscores could be later replaced.

!THIS! is just PERFECT
Works like a dream! I simply oversaw “insert placeholder”.
Oh this is so cool!
Thank you so very much!

Problem solved. Me is happy. Very happy!

Glad to help. :slight_smile:

And here is teaching edition example using AppleScript for anyone so inclined…

1 Like

Haha! Thank you!

And I do understand your script - that’s cool also.
I’ll give it a try imediately and report. There are still some groups that are not remamed correctly :wink: