Batch Compile and Post-Compile Automator Script

My workflow generally has me running compilation frequently. I like to take a look at my work in PDF, iBooks, Kindle, etc., especially when working with beta readers. So I usually find myself setting up a couple project presets for the various targets, then at various points, compiling to each of them. Three things would make this workflow much simpler:

  • Batch compilation - That is, let me set up multiple compilation presets that will be built in a sequence

  • Save the “front matter” selection in the preset so that I don’t have to change from “paperback” to “ebook” front matter when going PDF to iBooks

  • Let me select an Automator workflow to run when the compilation is finished (this allows me to move the output files around where they need to go and I even have a script that generates a TTS audiobook from a text file that Scrivener produces)

Love this app. Keep up the great work.

Thanks! I’ll pass this idea along to Keith, but I think that it is kind of dead on arrival, owing to its dependency upon the ability to save front matter settings into project presets. That notion has come up in the past, but there are technical issues that make that not very easy to cleanly do—and without that, I’m not sure how broadly useful a batch compile would be if the same content settings were being run for every preset.

However on that point you should already be able to use the operating system. Automator scripts can be saved as “Folder Actions” which do precisely what you’re talking about. Whenever a new item lands in the folder a script is attached to, the script runs against it (you would build any necessary file type filtering into the script).

Thank you for the reply.

That is a good point. I am a developer myself, but not familiar with the architecture of Scrivener. But if I had to work around a limitation like that, I’d probably look into storing the front matter setting as a part of the “batch” then instead of a part of the compilation preset and then just have the batch process change the front matter setting of the project before starting each compile. But obviously I’m not familiar enough with the code to know if that’s practical or not.

I did attempt that and it was extremely unreliable. Sometimes the script would run, sometimes it wouldn’t. Sometimes it would run more than once. I suppose that could be due to something on my system though. Maybe it’s because it’s a Dropbox folder which is also being “watched” by the Dropbox process.

Solving it wouldn’t be impossible, of course, the storage system as it currently is, is just not set up very well for the concept of their being multiple stored settings for project-specific data (Project Presets are only unique in that they only show up for the project itself instead of cluttering all compile menus). Like I say, I have put it on our long-term list, but to do this right, we would need a bit of a UI for it, a slightly different approach I feel. The notion of using presets to set up the batch is a good one, but the current UI for creating project presets is a bit more advanced in that it well out of the way—and I think batch outputs would be useful to many self-pubs (and maybe others as well), meaning that to do it right, it should be a little more than a button somewhere that triggers off of “hidden” features like project presets.

Do you use Keyboard Maestro? I have a script I use quite a bit that compiles without any interaction from me. It just calls up Compile, submits with current settings and confirms the overwrite on the prior output. Now in theory it would be possible to set up a custom KM script that rotated through presets. You would probably need full keyboard access enabled so that you could navigate through the Compile UI with Tab key events, in order to activate things like the Front Matter drop-down. I haven’t actually tried it, there may be a Tab-route that moves the active focus into the void that makes it impossible.

You know, I don’t know anything about how Folder Actions interact with Dropbox moderated folders. In theory it shouldn’t make a difference, the Dropbox software is supposed to merely reproduce a file and folder structure on every computer in the same way, but that once it does so, these files and folders are just like all others. However they do do some Finder hacking in anything lower than 10.10 (which now uses the official Extensions capabilities of the OS to add the status indicators and maybe right-click functions). Another thing I thought of, are you on 10.10 yet? I heard Folder Actions are a bit flaky on 10.10 (big surprise, everything else is), erratic execution is what I hear the symptom is.

Well, I hate to say “there’s another option but that it costs”, but I’ve been nothing but pleased with a neat little program called Hazel. For this kind of stuff, it’s brilliant, I’ve been using it for about seven years now. It works on a “watched folder” principle, you assign a folder to Hazel’s settings, and then you can build rules on top of that folder. You can set it up to monitor your compile folder and then look for certain file types and trigger scripts, including Automator workflows, (or perform many built-in functions) based on those matches. It’s very flexible, and if you’re into automating your Mac, I would consider giving the free demo a workout.