Search for long filenames

Hi,

Is there a way to search for filenames longer than a certain length?

I can use a Batch process to shorten such files once I’ve collected them…

… but I can’t find a smart search criterion to limit the find to filenames over a certain length. I can get a list of such filenames from the terminal with this command

find . -type f -exec basename {} \; | awk '{l=length($0);if(length>40)print length,$0}'

but how can I do this in DEVONthink, please?

Thanks!

1 Like

Interesting use case.

I don’t believe such criterion exists - but it should not be hard to incorporate a script to a batch action to do what you want. Applescript, js, shell…

Invoking the Masters: Oh Masters, heed our voices!

BTW: yes, I’m interested in doing this as well - catch some ridiculously long pdf names that pepper my databases.

Thanks!

I suppose I could just apply the batch action to every file in the database (because if a filename is under X in length, then presumably it will simply rename it to itself) but I’m a bit reluctant to do that in case there are unforeseen consequences…

This is an external AppleScript for use with smart actions. It’s easily modified, if needed.

1 Like

Thanks, Jim…

I found the script[1] and it looks simple enough[2], thank you!

I see that the script itself checks for filename length, and I take it that there isn’t a way of setting the search criteria to filename < X chars in the Smart Rule search section itself (to save a bit of time by avoiding having to run it on every document in the database)?

Thanks again for your help!


  1. It’s in ~/Library/Application Scripts/com.devon-technologies.think/Smart Rules/Truncate Filenames.scpt, and not com.devon-technologies.think3 if anybody else is looking for it. ↩︎

  2. Translation: I managed to work slowly through it and got a rough idea of what’s going on… ↩︎

I have no idea, maybe I’m misunderstanding this… but couldn’t you search for documents with long names (batch process), add a tag to these documents, and create a smart group that searches for this tag?

Thanks for your suggestion, but as I understand it, batch processes don’t search for files: they apply changes to files that have already been selected.

Therefore, to apply tags to files with too long names, I’d still be selecting all the files in the database, and if I’m going to do that, I may as well use a Smart Rule in the first place.

Obviously, if I’m misunderstanding something, I’d be pleased to hear it!

ha! The Gods have smiled on us

1 Like

I don’t want to hold you up with my speculations, also because I have no idea. That doesn’t work? Probably not :thinking:

Plus a smart group searching for this tag (long filenames).

I think that would work on files which you have already selected in a group, but it doesn’t actually select those files for you, which why you need the Smart search.

(And in any case, there’s no need for the tag, because you could change the name directly with regex substitution, as I did in my first screenshot, or run Jim’s script.)

1 Like

You’re welcome!

Correct, there is no such option.

1 Like

Cheers, Jim – running it across the whole database it is…

1 Like