Unless you use TextEdit or DelightEd a lot, you probably aren’t even aware of their sophisticated style features. Even if you do use their styles, it’s most unlikely that you know where those settings are stored, or how to hack them to extend either app’s features. In particular, you can use saved styles to enable TextEdit to create bi-modal Rich Text, which looks good whether displayed in Light or Dark Mode – something that DelightEd already excels at.
Setting a new style is quite simple. In either TextEdit or DelightEd – or any other app which uses this same feature in macOS AppKit – set some text up in the style that you want to access in future.
Click on the Style tool at the left end of the toolbar, and from its popup menu select the lowest command Show Styles… This will drop down the Style Editor panel, in which you can step through the different styles already used in your document using its Play controls.
In this case, the font and other styling set in that section of text is what I want to add as a new style. Then click on the Add To Favorites button.
Another drop-down panel will then prompt you for a name for your style, and whether you want to include font and ruler settings as part of it. These merit careful consideration because of their potential side-effects.
If you give your new style the same name as an existing style (apart from Default, which is special), after prompting to confirm, that existing style will be overwritten. It’s not hard to mess your styles up by overwriting those existing styles, but harder to recover the originals.
If you want your new style to change the style but leave the existing font unaltered, so that it works on a full range of fonts, leave the box to include the font unticked. If you do include the font (box ticked), it may also change the colour of the text when it is styled, and that can disable bi-modal colour settings if you aren’t very careful.
Before you try including any ruler change in the style, you’ll want to ensure that the ruler settings are correct using the Format / Text / Show Ruler menu command.
When you’re happy, click on the Add button to add your new style to the list of those available.
So far so straightforward. This all gets more peculiar when you try to discover where these custom styles are saved: not in the app’s preference file, where you’d expect, but in a single (per user) file which is shared by all apps which use this feature, in ~/Library/Preferences/com.apple.AppKit.TextFavorites.plist. You can use this strange behaviour to your advantage.
Using DelightEd, set up some styles which use the bi-modal text colour which looks black in Light Mode and white in Dark Mode. These are easy to set up and test in DelightEd.
Then open TextEdit, and apply those bi-modal styles to text in a document there. Save it as RTF, and open that document using DelightEd: you’ll discover that TextEdit can now generate and save bi-modal text, even though it can’t of course put its document windows into Dark Mode.
There is a bug in this AppKit styling feature in macOS Mojave 10.14.1: when you try to set a style for ‘regular’, i.e. non-bold non-italic text, you may find that it keeps being set in italic. This is because the Style Editor persistently sets it so.
You can work around this by manually editing com.apple.AppKit.TextFavorites.plist. Create a new style named Regular, for example, which uses the bi-modal text colour and tries to set the text non-bold and non-italic. Save this with both the include font and include ruler boxes disabled (no ticks). Then open com.apple.AppKit.TextFavorites.plist in your text editor, find the Regular key in the dictionary, and remove the NSFontTrait key and integer at the end of that dictionary, leaving just its NSColor entry.
If you’re unsure about that, the latest version of DelightEd comes with a property list which already has this Regular style included, in bi-modal text colour.
com.apple.AppKit.TextFavorites.plist is a fairly simple property list which can be manually edited. If you make a mess of it, or of the styles in an app which uses it, you can easily return it to its defaults by quitting all apps which use the file, trashing the com.apple.AppKit.TextFavorites.plist file, then opening TextEdit or DelightEd and using their Style Editor. This should create a fresh property list, which you can then modify as you wish.
In it, apart from the all-important bi-modal text colours (NSColor), most of the dictionary keys are drawn from NSFonts and related classes such as NSFontTraitMask. These are poorly documented, but you will note that setting NSFontTrait to 1 gives italic and 2 gives bold. It is easy to work out which keys do what, so that you can create your own style library without having to trudge through the Style Editor all the time.
The one style which you cannot alter is Default: if you try adding your own style using that name, you merely end up with two Default styles, one of which is the original and apparently immutable style. TextEdit offers in its Preferences explicit settings for its default plain and Rich Text styles, but those aren’t saved in com.apple.AppKit.TextFavorites.plist.
I hope that this support for custom styles in TextEdit, DelightEd, and any other apps which use AppKit’s style features proves useful.