Skip to main content
Inspiring
May 17, 2024
Answered

Script issue: Find/Change not recognizing a character style for bulled lists

  • May 17, 2024
  • 3 replies
  • 422 views

Hi everyone,

I'm trying to figure out why my Find/Change is not recognizing a character style ("Bullets") when I run the script below. Should I change anything on line 7?

Thanks for checking!
Rogerio

This topic has been closed for replies.
Correct answer rob day

This works—not sure if it will create other problems in a larger script:

 

var dcs = app.activeDocument.characterStyles.itemByName("Bullets")
var acs = makeCharStyle("Bullets");
acs.properties = dcs.properties;


app.findTextPreferences = app.changeTextPreferences = app.findChangeTextOptions = null;
app.findTextPreferences.bulletsAndNumberingListType = ListType.BULLET_LIST;
app.changeTextPreferences.bulletsAndNumberingListType = ListType.BULLET_LIST;
app.changeTextPreferences.bulletsCharacterStyle = acs
acs.remove()


function makeCharStyle(n){
    if (app.characterStyles.itemByName(n).isValid) {
        return app.characterStyles.itemByName(n);
    } else {
        return app.characterStyles.add({name:n});
    }
}

3 replies

rob day
Community Expert
Community Expert
May 18, 2024

Hi @Rogerio5C09 , I think the problem is app.changeTextPreferences.bulletsCharacterStyle is looking for an application (not a document) character style. So if I create a new document with a paragraph style that is referencing a document character style named "Bullets", and run this, I get false for the app characterStyle and true for the activeDocument character style:

 

 

var acs = app.characterStyles.itemByName("Bullets")
$.writeln(acs.isValid) //returns false
var dcs = app.activeDocument.characterStyles.itemByName("Bullets")
$.writeln(dcs.isValid) //returns true

 

 

If I reference either the acs or dcs variable rather than a name string with your script I get an error:

 

 

 

 

 

 

If I create an application level character style (all documents closed) named Bullets, then create the document I don’t get an error and the script works:

 

 

Not sure what the solution is—you might have to temporarily create an application level character style named bullets with the same properties?

 

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
May 18, 2024

This works—not sure if it will create other problems in a larger script:

 

var dcs = app.activeDocument.characterStyles.itemByName("Bullets")
var acs = makeCharStyle("Bullets");
acs.properties = dcs.properties;


app.findTextPreferences = app.changeTextPreferences = app.findChangeTextOptions = null;
app.findTextPreferences.bulletsAndNumberingListType = ListType.BULLET_LIST;
app.changeTextPreferences.bulletsAndNumberingListType = ListType.BULLET_LIST;
app.changeTextPreferences.bulletsCharacterStyle = acs
acs.remove()


function makeCharStyle(n){
    if (app.characterStyles.itemByName(n).isValid) {
        return app.characterStyles.itemByName(n);
    } else {
        return app.characterStyles.add({name:n});
    }
}
James Gifford—NitroPress
Legend
May 18, 2024

I'm not clear of the aim here, since the Character Style is inherently tied to the bullet Paragraph Style and thus can be chased down and/or modified by several different approaches... just not a direct search for the glyph and style in the text.

Robert at ID-Tasker
Legend
May 18, 2024

@Rogerio5C09

 

@James Gifford—NitroPress is right - bullets, when set as Bullets & Numbering of the ParaStyle definition, are "virtual" - they don't exist in the text as characters.

 

James Gifford—NitroPress
Legend
May 17, 2024

I haven't even taken two seconds to test, but — is it that the bullet list style doesn't actually appear in the searchable text? That is, that the style is applied at some lower level and does not actually show up as applied to the bullet glyph? (For that matter, can you search for bullet glyphs, or are they similarly "phantom" in the actual text?)

 

ETA: Tested; F/C does not find bullet character styles in use, nor bullet glyphs in use.

 

It will find both if they are used within other text, though.