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.

I have been experiencing strange issues with the InDesign history after running some of my scripts (AppleScript or JavaScript).

Specifically I have created a floating palette using ScriptUI in JavaScript that contains a list of icon buttons, that when clicked runs an AppleScript, using doScript. This is an example of the code:

Running an AppleScript from JavaScript.

app.doScript(File('the_script.scpt'), ScriptLanguage.applescriptLanguage, ["argument_1","argument_2"], UndoModes.fastEntireScript);

Since the AppleScripts are performing a lot of actions, and I only want to save all these actions as one single "undo", I apply UndoModes.fastEntireScript to the doScript.

When I have run this script just once, the undo history of the InDesign document in general is changed. When working normally and undoing once, it will undo the last many steps and not just one step as usual.

What is the problem here? Does changing the UndoMode for a single script execution change the documents UndoMode as well? Is it a bug, or just an user error - what can I do to prevent it?