Rename 500+ Documents by attaching the first line of the document

Is there an easy way to change the titles of many documents?
I want to attach the first line of the document to the document title.

The reason is, that many years ago I started with keeping a folder with documents (like 10 to 30 per year) like a diary. The title was like “2012-10-05-text” and the actual text starts with a headline.

Now I want to look through these but just according to the headlines - and the easiest way to do so seems to be to put all the headlines into the titles (without loosing the date in the title for easier sorting). So in the example I would like to change the title to something like “2012-10-05-text-Begin of Construction” (with or without the “text-”).

Is there an easy way to change that quickly?

I tried to sync to a folder, then change a title there and sync back, but the change of a title is not recognized. If this would work, I could write a program to change all the files and their names and then sync it back…

Thank you for all hints!

If I had that task, and I don’t and have not played with the idea–just thinking, I would export all the files from Scrivener to a macOS folder. Then, as you can write a program, I would also write a program (probably in Python) to change the file names to what I want based on content (first line as you mention) or something. I guess the program could be a complicated as needed. Then re-import all the newly named files back into a brand new Scrivener project.

1 Like

@rms is on the right track.

The wrinkle is that Scrivener fills the Binder titles from the .scrivx file, not from the individual documents, so for an existing project that’s where you need to make the change.

You can find the .scrivx file for a project by locating the project in Finder, right-clicking, and choosing the option to Show Package Contents. It’s XML, but reasonably human-readable.

WARNING: Directly editing the .scrivx file for a project is unsupported, entirely at your own risk, and can potentially render the project unusable. Make a backup AND make sure the backup is restorable before you even think about touching it.

(On the other hand, you can skip the scary .scrivx file editing if you import the modified files into a new project, since the new project will be a clean slate with no “knowledge” of the imported files.)

2 Likes

Thank you guys! Next time I will go this route you proposed.
I analysed my files better and found 200 are translations into other languages (which I do not need right now) and a third of the rest has already what I want. So I was left with about 200 documents.

Then I saw that the do not have all the same structure, some have a link as first thing on the page, some other text, some the actual headline.

So I was about to start programming on basis of the sync-to-folder text files… but then:

I just spent today three hours to do it all by hand - discovering on the fly other problems (missing documents etc).

I will consider the export/import solution (seems to be safer than manipulating the .scrivx) next time :slight_smile:

Thank you!!

I’m not sure if this will work for how you have your data set up, but something to keep in mind is that if you leave the title blank, it will automatically take from the synopsis card, or lacking that, the first line of the main text content. So if the first line is the heading, and it is complete, then all you need to do is clear the manually typed titles. So long as you don’t have synopses getting in the way, this will allow the title to be automatically driven by the content.

You can try it on one or two and see if that will work for you. The menu command that will help with this is, Documents ▸ Auto-Fill ▸ Clear Title. The command can be run on any number of selected items in the binder, corkboard or outliner view.

That is the “official” way of handling the core desire of having the title driven by text content. This will be used as the effective title for all practical purposes in the project’s tools. Export and folder sync will use it, searches will find them by this title, it will sort correctly. The only exception is compile—but in most cases if the heading is already in the content you wouldn’t want the compiler generating a duplicate of that title right above it anyway. There is a setting that would cause that to happen though, should you need it.

1 Like