Copy link to clipboard
Copied
After importing from Word, I often find myself with an unneeded style that InDesign thinks is in use somewhere. I try deleting it, and it asks what style to replace it with. But since I don't know where it's applied, I don't know what to replace it with. So I have to fire up Find/Change, select the styles menu, scan through my ~100 styles and select the one to search for. Why can't we have a right-click option to "Find this style" right from the Paragraph Styles pane? We can do that for colors, why not p-styles?
Is there any way to use scripting to accomplish this task faster than manually searching the F/C dialog every time? Maybe a script to add to the right click menu, or another way to search that would be faster. I'm curious if anyone else has a better idea for how I can accomplish this. Thanks!
Well, I spent a LOT of time researching and learning, but I think I've basically figured out a script solution on my own! Once the script is run, a new menu item appears in the right click menu. Clicking it will find the Paragraph Style in question and open the Find/Change dialog so that I can click "Next" to find more if need be.
Here's the script that I patched together; I'm sure it's not perfect and could be done better, but it works for me.
//https://community.adobe.com/t5/indesign-discussio
...
Copy link to clipboard
Copied
Here's a similar uservoice request that never got any traction, so maybe I'm asking for something that no one ever seems to need, but I could us it all the time!
Copy link to clipboard
Copied
Maybe that this style is nowhere used in the document, but is in use by another style in the document.
Copy link to clipboard
Copied
I use Magenta. Works every time.
—
Copy link to clipboard
Copied
Or change it to a spot color and use the separation preview panel to show only that color. You can zoom out and scan a number of pages at once.
Copy link to clipboard
Copied
Thanks for the suggestions! I'm looking for a way to jump right to an instance of the style though. That would come in handy even for styles I'm not intending to delete, and just need to quickly find within a 200 page doc.
Copy link to clipboard
Copied
I can see that as being useful, and probably relatively easy to implement since the basic components are already in place. But I don't find it too hard to use the search feature, either. It's mostly that case where a style isn't used but is the parent of others that I find tedious to clear up.
—
Copy link to clipboard
Copied
No more suggestions? 😞 I'm looking for a way to jump straight to an instance of a particular style, not to change its color and then go searching for it (while that idea can come in handy, that's not really what I'm looking for in this particular instance).
This is not just for use when trying to delete unnecessary styles. I could use it all the time for locating places in my long documents that I know should have a particular style applied. I'm sure there must be a way to script it, but I haven't thought of a way to accomplish it yet.
Copy link to clipboard
Copied
The search panel does exactly what you ask. It's just not a right-click option from the font list. I can see such a quick feature being useful, but there's only so much room on context menus and probably hundreds of "I wish" ideas for what should be there.
Is opening search, setting the format to the style you're seeking and clicking Next really all that onerous a process?
—
Copy link to clipboard
Copied
Not quite exactly. 🙂 When you've already got your mouse on one particular style (out of the ~100 or so in the panel) then yes, it seems a bit onerous to have to open 2 more menus and scroll through the 100 styles looking for the one I just had under my cursor. Seems like there should be a way to make things a bit more user friendly, that's all. I'm willing to take "no" for an answer if there's really no way to do it, but I'm not convinced that there isn't yet. 🙂
Copy link to clipboard
Copied
I think the alternatives have been exhausted.
There are hundreds of processes in ID that require no more and no less effort. There are so many operations that they have to be structured hierarchically like this. They can't all be on a one-click menu.
With Find open, the process is:
What you want would be:
Forgive me if I don't find that any faster or more efficient, or worth adding to the precious context menu space, or worth dev time.
That you have "hundreds" of styles raises other questions. I am trying to think of a project I've ever done with more than about thirty paragraph styles and maybe twenty character styles, and that list includes complex textbooks and reference books. In all good humor and kindly advice, I'd suggest that zippy searching for styles is not the most significant workflow issue you might have.
—
Copy link to clipboard
Copied
Point well taken. 🙂 I inherited these .indd files from others, so it's certainly not my choice that they have so many styles! The files are definitely more complex than necessary, and I'm working on that, but having this feature would help me with that, don't you see? 🙂
I agree with you that Adobe can't be expected to add every little feature that a person could ask for. Uservoice is full of suggestions that won't ever be implemented. However, the right-click menu in the Styles panel is not over-full; there's plenty of room for "Find this Style" just like there is in the color swatches menu (where "Find this Color" actually does exist).
I've been browsing these (and other InDesign) forums for a while, and have seen various scripts that made use of different menu commands and even added items to a right click menu, so I was curious if such a thing would be possible in the Styles panel. If not, that's fine; I won't die from 3 extra clicks. I was just curious if my life could be made a little easier, and whether such a thing was even possible. If I was a little more advanced in scripting, I'd give it a go myself, but I'm still a complete novice with scripting.
Copy link to clipboard
Copied
Scripting might have an answer but it would still be:
...or some variation. Even taking your request at face value, no editorializing, I can't really think of a way to streamline it except by routinely keeping Find open and parked to one side for ready service. Even the fanciest script can't read your mind or divine which style you want. 🙂
You might also look at hardware/keyboard/system macros, but there still has to be a 'select style' step in there somewhere.
—
Copy link to clipboard
Copied
I was thinking the script would create an addition item in the right-click menu. No scrolling necessary, my mouse is already on the style I want. Just right-click > "Find Style". Bam.
But like I said, I don't know if such a thing is possible, I just wondered if it is, or if anyone's tried something like that before.
Copy link to clipboard
Copied
Well, I spent a LOT of time researching and learning, but I think I've basically figured out a script solution on my own! Once the script is run, a new menu item appears in the right click menu. Clicking it will find the Paragraph Style in question and open the Find/Change dialog so that I can click "Next" to find more if need be.
Here's the script that I patched together; I'm sure it's not perfect and could be done better, but it works for me.
//https://community.adobe.com/t5/indesign-discussions/add-script-to-context-menu-on-paragraph-or-character-styles-panel/m-p/10814711#M168839
#targetengine "session"
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
main();
function main(){
// Add the new menu item
var theRtMenuStyleListItem = app.menus.item("$ID/RtMenuStyleListItem"),
theMenuName = "FIND this style";
// Remove any previous versions of the menu item and actions.
if( theRtMenuStyleListItem.menuItems.itemByName( theMenuName ).isValid ) { theRtMenuStyleListItem.menuItems.itemByName( theMenuName ).remove(); }
if( app.scriptMenuActions.itemByName( theMenuName ).isValid ) { app.scriptMenuActions.itemByName( theMenuName ).remove(); }
// Create the menu action, menu item, and event listener.
var theScriptMenuAction = app.scriptMenuActions.add( theMenuName );
var theScriptMenuItem = theRtMenuStyleListItem.menuItems.add( theScriptMenuAction, LocationOptions.AFTER, theRtMenuStyleListItem.menuItems.item(-1) );
var theScriptEventListener = theScriptMenuAction.eventListeners.add( "onInvoke", theScriptHandler );
}
function theScriptHandler () {
// Collect paragraph style name from context menu
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
var selectedStyle = app.menus.itemByName('$ID/RtMenuStyleListItem').menuItems.firstItem().name.replace(/Edit "(.*?)".../, "$1");
//https://community.adobe.com/t5/indesign-discussions/script-find-paragraph-style-under-the-folder/m-p/12834067#M470616
function getByName(styles, name) {
for (var i = 0; i < styles.length; i++)
if (styles[i].name == name) return styles[i];
}
var doc = app.activeDocument;
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.appliedParagraphStyle = getByName(doc.allParagraphStyles, selectedStyle);
// https://stackoverflow.com/q/41824622
var myResults = doc.findText();
app.select(myResults[0]);
// https://community.adobe.com/t5/indesign-discussions/select-text-based-on-paragraph-style-selected-in-paragraph-styles-panel/m-p/9935498#M104979
app.activeWindow.zoomPercentage = app.activeWindow.zoomPercentage;
//http://kasyan.ho.ua/tips/indesign_script/all/open_menu_item.html
app.menuActions.itemByID(18694).invoke(); //opens Find/Change dialog
}
Please feel free to recommend any changes or enhancements if you see anything that could be done better.
Copy link to clipboard
Copied
Well done for putting together the script!
It's not a regular script, inasmuch as it relies heavily on invoking InDesign menu actions. Ideally, one wouldn't want to do that, but in this case there is no other way AFAIK.
The one problem with your script is that it won't work with styles in groups, because the group name doesn't appear in the menu.
I did something similar a while ago, and figured out a way around that limitation. Have a look here: https://youtu.be/Sr7qOLq_w9I
Ariel
Copy link to clipboard
Copied
Thanks! That video demonstrates exactly what I was looking for!! You showed up a little too late. 🙂 But I'm glad I'm not the only one who has a similar use case.
Unless I'm mistaken, my script does work with styles in groups. (It has to, because most of my styles are found in groups). That's what the getByName function does; it takes the name of the style and searches through allParagraphStyles till it finds the right one.
getByName(doc.allParagraphStyles, selectedStyle);
One thing my script probably doesn't do properly though is handle style names that are the same but in different groups. However, that's not a problem for me, because all of my style names are unique.
Copy link to clipboard
Copied
Ah, right, I missed that. So yes, the only advantage then with my version is that it would be able to work even if 2 styles have the same name in different groups.
(By the way, I think [though not 100% sure] that if you download the demo of the script, the function to find the style continues to work even after the demo expires.)
Copy link to clipboard
Copied
Cool. Maybe I'll have to try out the demo. 🙂 I'm sure your script is better built and less prone to problems than mine, cause I am definitely a very amateur coder, and mine was literally pieced together with scraps of info and code that I found online that looked relevant!
One little issue with my script that bugs me is that sometimes when I right-click and "Find Style" the Find scope gets set to "Selection" and then when I hit "Next" in the Find/Change dialog I get an error that nothing more could be found, because it's only searching within the selection. So I'm not sure how to deal with that; can't find any info online about how to programmatically set the "scope" to Document for the Find/Change settings.
Copy link to clipboard
Copied
Hi,
I tried to use your script. Unfortunately, it doesn't work. Now I would like to remove the "FIND this style" item from the palette.
Can you recommend a solution?
Thanx a lot
E.
Copy link to clipboard
Copied
Save as a .jsx file in the InDesign scripts folder and run the script. Then right-click the Paragraph style and click 'Find this style'.
#targetengine "session"
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
function main() {
var theRtMenuStyleListItem = app.menus.item("$ID/RtMenuStyleListItem");
var theMenuName = "Find this style";
// Clean up old menu
try {
if (theRtMenuStyleListItem.menuItems.itemByName(theMenuName).isValid) {
theRtMenuStyleListItem.menuItems.itemByName(theMenuName).remove();
}
if (app.scriptMenuActions.itemByName(theMenuName).isValid) {
app.scriptMenuActions.itemByName(theMenuName).remove();
}
} catch (e) {}
// Add menu item and handler
var theScriptMenuAction = app.scriptMenuActions.add(theMenuName);
theRtMenuStyleListItem.menuItems.add(theScriptMenuAction, LocationOptions.AFTER, theRtMenuStyleListItem.menuItems.item(-1));
theScriptMenuAction.eventListeners.add("onInvoke", theScriptHandler);
}
function theScriptHandler() {
// Get the style name from the context menu (right-clicked)
var styleNameMatch = app.menus.itemByName('$ID/RtMenuStyleListItem')
.menuItems.firstItem().name.match(/Edit "(.*?)"\.\.\./);
if (!styleNameMatch) {
alert("Could not identify the paragraph style name from the context menu.");
return;
}
var selectedStyle = styleNameMatch[1];
var doc = app.activeDocument;
// Find the matching Paragraph Style object by name
function getByName(styles, name) {
for (var i = 0; i < styles.length; i++) {
if (styles[i].name === name) return styles[i];
}
return null;
}
var styleToFind = getByName(doc.allParagraphStyles, selectedStyle);
if (!styleToFind) {
alert("Style not found in document: " + selectedStyle);
return;
}
// Clear previous search settings
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.appliedParagraphStyle = styleToFind;
// Find all uses of the style
var myResults = doc.findText();
if (myResults.length === 0) {
alert("No text found using the style: " + selectedStyle);
return;
}
var foundText = myResults[0];
app.select(foundText); // This works without needing a manual selection
// Get the page the found text is on and show it
var tf = foundText.parentTextFrames[0];
if (tf && tf.parentPage && tf.parentPage.isValid) {
doc.layoutWindows[0].activePage = tf.parentPage;
} else if (tf && tf.parent instanceof Spread) {
// In case it's on the pasteboard or a masterless spread
doc.layoutWindows[0].activeSpread = tf.parent;
}
// Optional: slight UI refresh without changing zoom
app.activeWindow.zoomPercentage = app.activeWindow.zoomPercentage;
}
main();
Copy link to clipboard
Copied
Hey all, a sneaky way I do this without bothering with scripts etc. is to use the Table Of Contents system. Simply go to Layout > Table of Contents, then ask it to make a table of contents using only the style you're trying to locate. Make it add the page number if you wish so it's easier to find. In the example I've attached here I'm trying to locate all uses of a style called "C Head".
Then simply click anywhere on the spread to make your TOC and it will show all instances of that style being used.
Voila!
Copy link to clipboard
Copied
To help identify text using a particular paragraph style in InDesign, you can try these techniques:
...OR...
Hope that is helpful. Have a great day.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now