Copy link to clipboard
Copied
I use this simple JavaScript (Italic.jsx) that converts highlighted Open Sans text into italics:
app.selection[0].appliedCharacterStyle='Italic';
Worked until at least InDesign 16 but now produces this error:
Anyone have a tip on how to make this work again?
Copy link to clipboard
Copied
You sure the document has a Character Style called "Italic"?
Copy link to clipboard
Copied
Well it worked before on hudreds of documents and the font set was the same.
Copy link to clipboard
Copied
In addition to what @brian_p_dts mentioned also make sure that the style is not a part of a group. You could even try the following code snippet
app.selection[0].appliedCharacterStyle=app.documents[0].characterStyles.itemByName("Italic");
For example on how to deal/find style within groups you can refer to the following discussion. It talks about paragraph styles but the code for character style also remains the same mostly with changes only to the name of property and methods.
-Manan
Copy link to clipboard
Copied
That didn't work either, produces a similar #30477 error.
I created a workaround. Using the standard Shift-Command-I, which used to select Open Sans Condensed Italic because, I guess, that was first in the font menu. So I deleted that particular Italic and now it works but it’s not an optimal solution. 🫤
Copy link to clipboard
Copied
Please paste an image of your Character Styles panel of the document you are getting this error on that shows a named character style called Italic. If the document does not have that Character Style this script will not work. Does not matter if it has worked on hundreds of other documents. The script cares nothing about font sets.
Copy link to clipboard
Copied
If you don't want it to be depending on a character style, then the code is:
try { app.selection[0].fontStyle = "Italic"; }
catch(e) {
if (app.selection.length == 0) { alert("Select something!"); }
else if (!app.selection[0].hasOwnProperty("fontStyle")) { alert("Select something with a font style!"); }
else { alert("No Italic style available for this font! It might be named something else!"); }
}
Copy link to clipboard
Copied
Make sure that that your character style's name is really Italic. There could be an invisible character in the style's name. I've seen quite a few cases of a style name that had a return at the end or a tab. You don't see that in the panel, but you can try this: apply the style to some text, then click somewhere in that text and run this script:
app.selection[0].appliedCharacterStyle.name.length
In your case it should return 6.
The problem can happen if you (or some other user) copied a name and used that to name the style.
To fix a problem like this, simply re-type the name in the panel.
P.