In my dream world, all received texts for books etc. is marked up using styles from e.g MS Word. In my real world, that is unfortunately rarely the case.

I have written this script to help in the situations where a long text is formatted quite consistently, different headings are perhaps marked with bold and in a bigger font size, quotations are italic etc.

Walkthrough

I have imported a text file in InDesign, but it is not marked up with styles correctly, and there would be no reason to reuse the current styles. So I will just delete all the imported styles, but preserve the formatting, so the style panels are all clean.

Text is imported and all styles are deleted.

Text is imported and all styles are deleted

Placing the cursor in the text flow somewhere will let the script know what story I want it to work with. Now, activating the script, it will automatically run through all paragraphs in the story, check how they differ from the Basic Paragraph style, and create new one's where needed.

In this case, the only differing thing is the oblique font style.

In this case, the only differing thing is the oblique font style

Each time it has created a new style, it will also check if that style will apply to the paragraph it is checking, ensuring that all the paragraphs with the same text formatting will end up having the same paragraph style.

Furthermore it will also check all text for any local formatting within the paragraphs, so bold text will get a character style, italic text, coloured text etc. Also these will be reused, so where its applicable the same style will be used.

An example of an automatically created paragraph and character style.

An example of an automatically created paragraph and character style

Where you go from the result of a lot of AutoStyles is up to you. I prefer to create new styles, then delete the AutoStyles one by one from the panel, replacing them with the new styles.

The script will unfortunately not do all the hard work for you, but is a great tool in cleaning up messy documents!

The script

The JavaScript can be downloaded here: auto_create_p_c_styles.jsx.

You can add it to your Scripts palette and run it from there. To do that, place the file inside the "~/Library/Preferences/Adobe InDesign/Version 6.0/Scripts/Scripts Panel" folder.

Note that depending on the length of your document, the script might take a while to run.

Known bugs:

  • If the first word of a paragraph is "locally formatted", the script will think that is the "general formatting" of the whole paragraph.

I have continued my AppleScript to JavaScript translation and are ready with the other two "bigger" scripts!

This would be the Automating anchored object creation script, which will help you automate creating those anchored text frames for margin text, captions etc.

By specifying which character styles or paragraph styles from a text story you want cut out and placed in an anchored text frame, it will complete the task for you.

And the Marking up index words from colours script, which is written with the intention to fit into an InCopy workflow, since you can't mark up index words in InCopy. But it can also be used without InCopy. Basically it will find all words with a specific colour swatch and add them as index words.

I hope you will enjoy! And please be sure to report any bugs you might come across.

Yesterday I twittered I was »Considering trying to translate my free InDesign AppleScripts to JavaScript. Could potentially learn a lot from it« (link).

Today I decided to try it out.

Now the first translation is available!

I decided to start out with one of the scripts I find most useful, fixing paragraph style combinations.

The script allows you to select a paragraph style combination and change it to another. For instance, if you need to search for all subheading followed by indented paragraph combinations and change the indented paragraphs to none-indented, this is the tool for you.

Translating the script should enable you to use the script in Windows as well, so go ahead and try it out!

I will soon begin translation of my other scripts, but I will not promise that all scripts will be translated, neither now or in the future - I'm still better at AppleScripting.

If you often create books with text in the margin, you probably know the importance of being able to use anchored objects. The only downside to anchored objects are creating them - especially if it is a large book with a lot of text needed to be moved.

I have written a script to help in this process. In short, it does all the hard work for you.

You can easily just download the script, run it, and you will probably quickly figure it out, but I still want to explain how I found the workflow easiest.

The workflow

First of all, you have to ensure that the text you need moved to anchored text frames are marked up using either a character style or a paragraph style.

Text with paragraphs marked up as margin text.

Text with paragraphs marked up as margin text

The second thing you should prepare, is an object style for the anchored text frames. By creating an object style you can easily change all locations of the frames at a later point, the look etc.

The Anchored Object Options.

The Anchored Object Options

It is also a good idea to specify a paragraph style in the object style, if you would like it to be another than the referring text.

You can specify a paragraph style for your text frame.

You can specify a paragraph style for your text frame

The third thing you have to find out, is what the height and width of the anchored frame should be. You have to type in these values when the script is executed. The values can be typed in as any unit, InDesign will automatically convert it to millimeters.

The scripts main window where the options is set.

The scripts main window where the options is set

When the script is executed, you will have the option to either find and move character styles or paragraph styles to anchored text frames. The option to delete matches gives you the choice of leaving the "moved" text in the main text flow.

For character styles, the anchor will be placed after the text, in the beginning of the following word. For paragraphs, the anchor will be placed as the first thing in the next paragraph.

The final result in this case.

The final result in this case

The script

The AppleScriptJavaScript can be downloaded here: create_anchored_frames.jsx.

You can add it to your Scripts palette and run it from there. To do that, place the file inside the "~/Library/Preferences/Adobe InDesign/Version 6.0/Scripts/Scripts Panel" folder.

You probably know the issue, which I have also mentioned in a previous blog post - you can't search on paragraph style combinations using GREP search.

The obvious case where this could be handy, is if your story contains a lot of subheadings and indented paragraphs, and you want to make all indented paragraphs, not indented if they are appearing below a subheading. As I mentioned in the GREP wishlist article my current way to do this is by exporting the story as tagged text, and do a regular expression search in a text editor.

Subheadings followed by an indented paragraph.

Subheadings followed by an indented paragraph

But not anymore!

Today I wrote a small AppleScriptJavaScript to take care of the issue - it is actually quite simple and doesn't require much introduction. Once you have launched the script, you are asked what pair of styles you are looking for, and what you want them changed to:

Fix paragraph style pairs.

Fix paragraph style pairs

The script will search the current story and fix all occurrences of the pair.

The AppleScriptJavaScript can be downloaded here: fix_pstyle_pairs.jsx.

You can add it to your Scripts palette and run it from there. To do that, place the file inside the "~/Library/Preferences/Adobe InDesign/Version 6.0/Scripts/Scripts Panel" folder. It should work in CS3 and CS4 in Windows and Mac.