AppleScript for syntax coloring?

A lot of my writing involves code - generally HTML links or formatting. I’ve already discussed the idea of syntax coloring in Scrivener, and Keith has made it clear that he’s not interested.

However, I wonder if anyone knows whether Scrivener’s limited AppleScript support would allow a script to, say, search for HTML tags and change their colors? Personally, all I need is for tags to stand out, so I don’t get confused when I’m working.


I created an AppleScript recently that adds the text “(CONT’D)” to character blocks, if the previous character block was for the same person. You could use this as a starting point for your script. It’s a bit tricky working out how text is accessed via paragraphs, ranges and the like in AppleScript, so hopefully my work can give you a leg up!

My blog entry (including the script) is at Good luck!


Hi Mark,

Adding “Cont’d” after the Compile process is a very cool idea. Could you walk me through the logic you’ve got going there? How does it know that the character name isn’t occurring at the start of a new scene, for instance? And does it take parentheticals into account?

I’m curious, because I think this would be a neat idea to have as part of Compile itself - a tickbox somewhere that will add “Cont’d” where necessary to the compiled document.

Thanks and all the best,

Hi Keith,

The script was written quickly to help me finish off a script for a competition entry, so I didn’t worry about checking for the start of a new scene, etc. in the logic. Basically, it finds a new character block via the paragraph indent, and if the character name is the same as the previous one, it adds (CONT’D).

Checking for a scene heading could be added to this script, by checking for a line in all caps indented by the left indent value, which would zero out the saved character name variable, but you run the risk of doing this unintentionally if an action line is in all caps as well!

It’s a nasty way of working with text, because it’s quite fragile, but it worked for what I needed at the time :slight_smile: Of course, if you’re storing tags in the text that tell Scrivener when it should display a character block, etc., you could probably loop through these to add (CONT’D), as well as across page breaks.

It’d be great to see this happen, so please let me know if I can help in any way.


Hmm, actually, looking into this it seems that adding a “CONT’D” isn’t universally used after character names when interrupted by action. They say that it’s not essential in the BBC screenplay specs for Hollywood scripts ( … enplay.pdf) and also I found numerous debates on scriptwriting sites about whether it was needed.

If you do need it, Scrivener has an auto-complete set up for it, so you can type a space and a bracket after the character name and choose “CONT’D” from the suggested list of completions that pop up.

The place where it is used almost universally, at the beginning of a new page following a “MORE”, Scrivener unfortunately can’t help you with at this stage, as that takes some rather advanced layout (because it means laying everything out, finding broken action sections, splitting them up at the right place and suchlike) which is the sort of stuff Scrivener leaves to Final Draft and suchlike.

So, sorry to get your hopes up! This seemed like a cool solution and is indeed great as an AppleScript but would probably only be of limited use in the program itself.

Many thanks,

OK thanks Keith. I did get about 60% of the way towards automatically adding (MORE) and (CONT’D) over page breaks, but as you say, it is challenging… perhaps when I’m at a loose end on a rainy day (ha!), I’ll finish it.