Listing Labels

Does anyone know of a way of listing all the labels used in selected series of scrivenings?

I’m working on a oral history book which consists of something like 100 different interviews. As I edit, chopping the interviews up and moving them around, I’m tracking the interviewees with labels. It works well. But at the end I’ll be thinking about indexes and writing biographies. Getting during the compile stage a simple list of the labels (interviewees) that appear in each chapter will be extremely welcome.

Is there a way Scrivener can spit out such info? Perhaps using placeholder/s? Or will I need to do it manually?

Not listing labels in a separate list as such, but you can certainly build a compile format to output metadata and title only. I do something similar with my outline compile format. To get close to what you describe, turn off the notes and synopsis columns. Hope this helps!

Ah, that’s great idea! It doesn’t quite work for me because it churns out a chunk of extra data, but it has nudged me into realising I can simply set up a compile format with all the content columns turned off and <$label> placeholders placed into the speaker text prefixes.

Then I can use BBEdit (i.e. any good text editor) to delete duplicate lines in the resulting text file to get a simple list of all speakers. Job done! Thanks so much for the tip - I’d otherwise have floundered around on this for much longer!

And if you’re going to plain-text anyway (as it sounds would be sufficient since you’re using BBEdit), you can toss a simple Mac command to cut out this extra step, into your compile settings, in the Processing compile format pane. Here is an example compile Format with two different options:

  1. By default it will strip out duplicates, but also number the instances of such duplicate, and then sort the list in descending order by those instances. So if you have 15 uses of the label “Green” it will print “15 Green”, followed by “12 Blue” and so on.
  2. If you go into the Processing pane and click the Edit Script button, you’ll find there is a simpler command that is commented out. Swap the commenting in this script to have it output a simple unsorted list with all duplicates removed. (3.08 KB)

Oh, that’s fantastic - I had no idea Scrivener could process compiled txt files! And seeing the counts is genuinely extremely useful.

(By the way, for anyone following this, I initially set it to compile to a filename with capital letters and spaces, and the script didn’t like that at all.)

It’s not quite perfect for me… I have my compile set to place a chapter name (starting with a #), then the labels, and then an empty line before the start of the next chapter, like this

[code]Hiromasa Iwasaki
Toru Hidaka

T&E Soft

Mitsuto Nagashima
Tokihiro Naito
Yasuo Yoshikawa[/code]

Is there a way of getting the script to sort within each chapter group of labels, rather than globally?

(If it isn’t possible, or the solution is extremely complex and demands lots of your time, please don’t worry!)

Yeah that would be an interesting problem to solve. The command-line tools I made use of are made for simple file parsing and don’t really have many options within them for designating some lines as being ignored, etc., or to group areas within a single file as being separate sorting instances. You’d need a more full-blown script for that, something that can go through the file, programmed to recognise sections as starting with “#”, and then collect each following line (up until the next section) into an array and run the sorting and duplication removal within that block, then move on to the next.

It wouldn’t be too difficult, if you know a little Python or Ruby (or any interpreter), you can throw some pretty complicated stuff into that “Edit Script” window, and of course even switch it over to executing through the shell, where what you’re calling even has modules, classes, makes use of databases, networking—really the sky is the limit once you get into the implications of what this compile pane gives you.

Thanks, Amber - I had a quick look at the options for the sort command and figured it didn’t give that kind of flexibility. Perhaps I’ll have a fiddle one day, but for now I suspect it’ll take more time than it’d save. Really appreciate your help here!