Automated numbering of items?

I’ve got a set of 27 files that I want to move into a single group within a DTP database. I want to rename each file with the word “Lesson” and a number: Lesson 01, Lesson 02, etc.

Each file currently has a unique but meaningless filename, like dfbff151-69b9-46dd-ac51-5b1f73b06c3b.pdf.

The numbered sequence should reflect the creation date and time of the item. In other words, Lesson 01 was created before Lesson 02, etc.

Is there a way to make this happen in DTP, or do I need to change the file names manually, either before or after they’re transferred to DTP?

Thank you!

…?

Applescript

So, nothing already written? Even if I were capable of learning AppleScript, I doubt I’d use it often enough to justify the time.

In any case, there’s always the option of manual renaming this set of files. That’s something at which I do have a lot of experience :slight_smile:

Something like this (as external JavaScript script in a smart rule)

function performsmartrule(records) {
  const sortedRecords = records.sort( (a,b) => b.creationDate() - a.creationDate());
  for (i = 0; i++; i < records.length) {
    sortedRecords[i].name = `Lesson ${i+1}`;
  }
}

Test on copies of your files first!

1 Like

Thank you, chrillek! I’ll give this a try and let you know. I really appreciate your help, as this is something I’m doing fairly often.

There was a typo in the original script. Please make sure to use the current version.

While it doesn’t seem to be a great burden to manually rename 27 documents, if you don’t need to prefixing zeroes…

  1. Sort the documents by creation date.
  2. Choose Tools > Batch Process.
  3. Use Change Name with Lesson, then Control-Click in the text field and choose Insert Placeholder > Index

Alternatively, you could use Counter which would prefix with up to five zeroes.
On a side note, the number of zeroes used in a Counter can be set with the CounterDigits setting in Appendix > Hidden Preferences section of the built-in Help and manual. This is set via a Terminal command, per the instructions at the top of the page.

4 Likes

That did it, Bluefrog. Thank you. That’s a technique I’ll be using fairly often.

chillek, I was enjoying experimenting with the script you kindly wrote. I’m putting it in a safe place so that when I’m in a position to advance my nearly non-existent knowledge of rudimentary scripting, I’ll have something to work with.

Both of you gave me deeper insight into the power of DEVONthink. So cool!

Occam’s Razor :wink:
You’re welcome :slight_smile:

1 Like

In fact you can do this in the Finder. Select the files you want to rename and choose for File → Rename… menu:

:grinning:

1 Like

That doesn’t help for files imported into DT. It’s perhaps possible, but already selecting those files is probably very tedious. And one shouldn’t fiddle with database internals with Finder, anyway.

1 Like

While that is technically true, that operation should only be done with indexed files or before they’re imported into DEVONthink. As @chrillek mentioned, you should not be messing about in the internals of a database, if that’s what you were thinking of.

That’s also possible using batch processing and the Index placeholder.

aka K.I.S.S.

1 Like

Look for an app called File Mangler on the App Store. It will allow files to be renamed in a number of different ways before they are imported to DT Pro.