Copy link to clipboard
Copied
Hello Experts,
Below is the code, i am using to alert machine generated small cap found in document or not.
This will give alert only if i run the script. Is it possible to make a panel which run this script in backend and show the results via javascript? (like preflight panel)
I hope this can be done by plugin. But need to know is it possible to do the same in javascript.
var myDoc = app.activeDocument;
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.capitalization = Capitalization.SMALL_CAPS;
var myFinds = myDoc.findText();
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
if (myFinds.length == 0) {
alert("No Small Caps found");
}
else {
alert("Small Caps found");
}
Thanks in advance.
Karthi
...// VERY VERY VERY ROUGH STARTER GUIDE
// add checks and optimizations yourself!
#targetengine smallcaps
(function () {
// just for debug purposes remove the eventListeners if they exist and add them again
// for release check if they exist and create them of if they don't
app.eventListeners.item("onAfterDocSmallCaps").isValid && app.eventListeners.item("onAfterDocSmallCaps").remove();
app.eventListeners.item("onSelectionChange").isValid && app.eventListeners.item("onSelectionChange").r
Copy link to clipboard
Copied
Can run it as an idle task, just make sure to set large enough time gap. (4000+?)
Copy link to clipboard
Copied
Hi Trevor, Thanks for your reply. Hope i was not explained clearly. The above script is working fine and it is used to find small caps. I just want to know, is it possible to make a side panel which give the results promptly. If i introduce an error it will show the results immediately in that panel. If i remove the smallcap, then it will show no error. c++ plugin can make this kind of panels. But need to know it is possible in javascript or not. Am not sure now i explained little bit more. Thanks, Karthi
Copy link to clipboard
Copied
Hi Karthi,
Try this,
#targetengine "session";
app.menuActions.itemByID(119614).eventListeners.add("beforeInvoke", smallcap);
function smallcap(event)
{
alert("Small caps should not be used in this document");
event.stopPropagation();
event.preventDefault();
}
Put this script in the 'startup scripts' folder and restart indesign. Please note that it will work only when you press ctrl+shift+H.
Regards,
Chinna
Copy link to clipboard
Copied
Hi Chinna,
Thanks for your response. It works fine but this is not my requirement.
I hope still am not explaining clearly.
#targetengine "session";
var myDoc = app.activeDocument;
var stories = myDoc.stories.everyItem ().getElements ();
var myFind = new Array(); var myCounter = 0;
//-----------------------------For display---------------
var w = new Window ("palette", "Hyphenated words");
var list = w.add ("listbox", undefined, "", {numberOfColumns: 1, showHeaders: true,columnTitles: ["Hyphenated Word"], columnWidths: [185]});
list.maximumSize.height = $.screens[0].bottom-200;
var myStory_id = new Array(); var myitem_id = new Array();
//------------------------------------------------
main();
displayWindow();
if (myCounter > 0){
w.show();
}
else { alert("Double Hypehnation Not Found"); }
function main(){
var lineCount;
myResetFindChangeGrep ();
app.findGrepPreferences.findWhat = "(\\w+)([-~=])(\\w+)";
var myIndex = new Array();
for (i=0; i<stories.length; i++){
myFind = stories.findGrep(true);
for (j=0; j<myFind.length; j++){
lineCount = myFind
.lines.length; if (lineCount>1){
var story_id = i; var myFind_id = j;
var myText = myFind
.contents; addItem(myFind
, i, j); myCounter++;
}//End if
}//End of Find Length
}//End Story length
//alert(myIndex.length);
}
//------------------------Function Declarations--------------
function displayWindow(){
//window declared as global variable here
var panel1 = w.add('panel');
panel1.minimumSize.width = 210;
var group1 = panel1.add('group');
group1.orientation ='row';
var close_ = group1.add ("button", undefined, "Close", {name: "ok"});
group1.add("statictext", undefined, "");
close_.maximumSize.width = 55;
list.onDoubleClick = function ()
{
if (this.selection != null ) {
var myIndex = this.selection.index;
var storyNum = myStory_id[myIndex];
var findNum = myitem_id[myIndex];
var selectText = myFind[storyNum][findNum];
app.select (selectText, SelectionOptions.replaceWith);
app.activeWindow.zoomPercentage = 200;
}
}
close_.onClick = function () {w.close ()}
}
function addItem(myItem, sto_id, item_id){
list.add ("item", myItem.contents);
myStory_id .push(sto_id);
myitem_id .push(item_id);
}
function myResetFindChangeGrep(){
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
}
This script is to find double hyphenation text. When you run this it will create a side panel which contain the double hyphenated words. With this panel we can find the text location by double clicking the text in the panel.
Like this can we create a panel and if i apply smallcap then it will appear the error in that panel. If i remove that then it will show no error.
See the below screenshots:
This is our basic preflight report showing in indesign.
Regards,
Karthi
Copy link to clipboard
Copied
// VERY VERY VERY ROUGH STARTER GUIDE
// add checks and optimizations yourself!
#targetengine smallcaps
(function () {
// just for debug purposes remove the eventListeners if they exist and add them again
// for release check if they exist and create them of if they don't
app.eventListeners.item("onAfterDocSmallCaps").isValid && app.eventListeners.item("onAfterDocSmallCaps").remove();
app.eventListeners.item("onSelectionChange").isValid && app.eventListeners.item("onSelectionChange").remove();
app.eventListeners.item("afterSelectionChanged").isValid && app.eventListeners.item("afterSelectionChanged").remove();
app.eventListeners.add("afterOpen", checkForSmallCaps).name = "onAfterDocSmallCaps";
app.eventListeners.add("afterSelectionAttributeChanged", checkForSmallCaps).name = "onSelectionChange";
app.eventListeners.add("afterSelectionChanged", checkForSmallCaps).name = "afterSelectionChanged";
const capMessage = ["No Small Caps", "Yes Small Caps"];
var scui = new Window('palette');
scui.caps = scui.add('staticText');
scui.caps.minimumSize.width = 200;
scui.show();
function updateUI(yep) {
if (updateUI.cache === yep) return;
updateUI.cache = yep;
scui.caps.text = capMessage[yep];
}
function checkForSmallCaps(ev){
var sel = app.selection;
if (sel.length) {
sel = sel[0];
if (sel.properties.baseline) {
updateUI(+(sel.capitalization == +Capitalization.SMALL_CAPS));
}
}
}
})();
Copy link to clipboard
Copied
Hi Trevor,
Awesome
It almost close to my requirement. But one more thing, it show the errors only i place the cursor in that text. Here is the screenshots of your script:
Is it possible, this will check even when we insert the smallcap somewhere in the document without our knowledge?
Thanks,
Karthi
Copy link to clipboard
Copied
Hi Karthi
Just add a function (or event condition) which does a text search for small caps.
Make the after open event execute that function. Also have an idleTask fire the event but be very careful not to set the idle time to too short otherwise it will interfere with performance quite badly.
I'll be back on Sunday if you need more help but try manage yourself.
HTH
Trevor