Quantcast
Channel: Adobe Community : Popular Discussions - InDesign Scripting
Viewing all 15932 articles
Browse latest View live

Pass variable from JSX to VBS

$
0
0

Hello,

 

With ExtendScript I'm attempting to pass arguments to a VBS script from inside of a JSX script. I see that the arguments can be passed but I'm not sure how to retrieve those from inside of the VBS shell.

 

This is the example from AppleScript on OSX to read some text from a file using the cat command.

 

// establish array

ARG = [];

// establish variable

pathARG = "/path/to/file";

// push variable into array

ARG.push( pathARG );

 

// create AppleScript

var readTextScript = 'set filePath to item 1 of arguments\r'

readTextScript += 'do shell script "cat " & filePath';

// execute script with arguments

myResult = app.doScript( readTextScript, ScriptLanguage.APPLESCRIPT_LANGUAGE, ARG );

 

And here's an attempt to do the same with VBS script using the ReadAll command which fails.

 

// create VBS script

var readTextScript = 'Set wshShell = CreateObject( "WScript.Shell" )\r' +

'Set filePath = wshShell.Arguments.Item(0)\r' +

'Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile(filePath,1)\r' +

'strFileText = objFileToRead.ReadAll()\r' +

'objFileToRead.Close\r' +

'returnValue = strFileText';

var myResult = app.doScript( readTextScript,ScriptLanguage.VISUAL_BASIC, ARG );

 

Error message: "Object doesn't support this property of method: 'wshShell.Arguments'

 

Any help would be appreciated!

 

--
Jared Annear


Indesign script for removing pages with specific content/keyword...

Compare InDesign Files

$
0
0

Hi,

   

     I want to compare InDesign files. Is there any method to compare 2 InDesign Files in application or code?

 

    Need to compare texts, objects and designs and generate report if have any variations.  Is it possible in InDesign using javascript?

Delete comments from active page

$
0
0

Hi, is there any way to delete (or mark as resolved) all pdf comments from the current page using a script? Thanks.

Smart casing for Title Case with Script

$
0
0

Hi,

I have working on a very large document which requires conversion of a particular paragraph style to Title case with smart casing such that words like A, An, The and so on and so forth, cover sentence case style, and other words follow Title Casing. In order to follow the approach I came across a brilliant script (bg thank you to @Dave Saunders) which converts the heading with smart casing:

Changing Sentence Case in a Paragraph Style? - Adobe Indesign Windows

//DESCRIPTION Converts selected text to title case smartly

//Smartly means that articles, etc. are ignored
//and internal capitals of recognized words are retained.

ignoreWords = ["a","and","the","to","with","in","on","as","of","o r","at","is","from","for"];
intCaps = ["PineRidge","InDesign","NJ","UMC"];
try
{
myText = app.selection[0].texts[0].contents;
}
catch(e)
{
exit();
}

theWords = myText.toLowerCase().split(" ");

//First word must have a cap, but might have an internal cap

myNewText = "";

for (var j = 0; theWords.length > j; j++) {
k = isIn(intCaps,theWords[j])
if (k > -1) {
myNewText = myNewText + intCaps[k] + " ";
continue;
} else {
if ((isIn(ignoreWords,theWords[j]) > -1) && (j != 0)) {
myNewText = myNewText + theWords[j] + " ";
} else {
myNewText = myNewText + InitCap(theWords[j]) + " ";
}
}
}

app.selection[0].texts[0].contents = myNewText.substring(0,myNewText.length - 1);

function isIn(aList,aWord) {
for (var i = 0; aList.length > i; i++) {
if (aList[i].toLowerCase() == aWord) {
return i;
}
}
return -1;
}

function InitCap(aWord) {
if (aWord.length == 1) {
return (aWord.toUpperCase());
}
return (aWord.substr(0,1).toUpperCase() + aWord.substring(1,aWord.length))
}

 

The issue is that I have around 100+ headings for which I have to do this. In order to find a quicker approach, I found another script by Dave Saunders updated by Zalmanf which changes casing of a particular paragraph style at once without smart casing:

Updating Dave Saunders find style/change case script

//DESCRIPTION: Update of Dave Saunder's ChangeCaseOfSelectedStyle script to replace either Paragraph and Character Styles

if ((app.documents.length != 0) && (app.selection.length != 0)) {
myDoc = app.activeDocument;
myCStyles = myDoc.characterStyles;
myCStringList = myCStyles.everyItem().name;
myPStyles = myDoc.paragraphStyles;
myPStringList = myPStyles.everyItem().name;
myCaseList = ["Uppercase","Lowercase", "Title case", "Sentence case"];
myCases = [ChangecaseMode.uppercase, ChangecaseMode.lowercase, ChangecaseMode.titlecase, ChangecaseMode.sentencecase];

var myDialog = app.dialogs.add({name:"Case Changer"})
with(myDialog){
  with(dialogColumns.add()){   with (dialogRows.add()) {    with (dialogColumns.add()) {     staticTexts.add({staticLabel:"Character Style:"});    }    with (dialogColumns.add()) {     myCStyle = dropdowns.add({stringList:myCStringList,selectedIndex:0,minWidth:133});    }   }   with (dialogRows.add()) {    with (dialogColumns.add()) {     staticTexts.add({staticLabel:"Paragraph Style:"});    }    with (dialogColumns.add()) {     myPStyle = dropdowns.add({stringList:myPStringList,selectedIndex:0,minWidth:133});    }   }   with (dialogRows.add()) {    with (dialogColumns.add()) {     staticTexts.add({staticLabel:"Change Case to:"});    }    with (dialogColumns.add()) {     myCase = dropdowns.add({stringList:myCaseList,selectedIndex:0,minWidth:133});    }   }  }
}
var myResult = myDialog.show();
if (myResult != true){  // user clicked Cancel  myDialog.destroy();  errorExit();
}  theCStyle = myCStyle.selectedIndex;  thePStyle = myPStyle.selectedIndex;  theCase = myCase.selectedIndex;  myDialog.destroy();  app.findTextPreferences = NothingEnum.NOTHING;  app.changeTextPreferences = NothingEnum.NOTHING;  if (theCStyle > 0) {  app.findTextPreferences.appliedCharacterStyle = myCStyles [theCStyle];  }  if (thePStyle > 0) {   app.findTextPreferences.appliedParagraphStyle = myPStyles [thePStyle];  }  var myFinds = myDoc.findText();  myLim = myFinds.length;  for (var j=0; myLim > j; j++) {   myFinds[j].texts[0].changecase(myCases[theCase]);  }


} else {
errorExit();
}


// +++++++ Functions Start Here +++++++++++++++++++++++


function errorExit(message) {
if (arguments.length > 0) {  if (app.version != 3) { beep() }  alert(message);
}
exit();
}

 

Both these scripts are amazing and really help in improving the efficiency of the work flow, however, in order to apply smart casing I have to first run the second script to change casing of all headings and then apply first script for smart casing output.

 

Is it possible to amalgamate both scripts in such a way that we are able to change the case of any of the style at once with smart Title casing.

 

Any kind of guidance would be greatly appreciated. Also, Thank you Dave Saunders for sharing your vase pool of knowledge with the world. Big thank you!

Regards,

Aman Mittal

[ID-CS5][JS] Pasting into a rectangle at same position

$
0
0

Hi,

 

I am trying to make a script and have been successful to a point...

 

I have content on a layer labeled "copy-layer"

Also, rectangles and polygons marking areas of copy-layer on another layer called "export-layer"

I want to copy all of the content from copy-layer inot each individual shape from  export-layer

This will help me export selection(i.e. individual shape) to JPEG.

 

I struggling to pasteinto() theses shapes and locate copied content at same position as it was on copy-layer.

 

Any help will be appreciated.

 

Thank You

 

 

johnD

How to hide ONLY column guides in indesign?

$
0
0

Is there a script to toggle the visibility of ONLY the column guides in inDesign, leaving the ruler guides and margins visible?

dropdown list background color change

$
0
0

Hey there,

 

i am working on a dropdown list to show my swatches in order on a panel. I would like each index color to have the background color of that number listed.

I am looking all over and struggling to find background colors of dropdown list. is this possible?

 

here is my code thus far.

 

 

 

 

#targetengine "session"; //not needed in Illustrator / After Effects

 

 

var w = new Window("dialog", "Swatches!", undefined);

     var panel = w.add("panel", undefined, "Swatches");

     panel.orientation = "row";

 

 

    //UI design

     var ddl = panel.add("dropdownlist"); 

     var colorSelectBtn = panel.add("button", undefined, "SELECT");

     var closeBtn = panel.add("button", undefined, "CLOSE");

    

    //variables

    var activeDoc = app.activeDocument;

    var swatches = activeDoc.swatches;

   

    //loop through the swatches

    for(var i = 0; i < swatches.length; i++) {

        //indexing swatches

        var mySwatches = swatches[i].name;

        //adds to dropdown

        ddl.add("item", mySwatches);

    }

 

 

     ddl.selection= 0; //dropdown list  first swatch index

 

 

    //swatch selected

    colorSelectBtn.onClick = function() {

       

       if (!(app.selection[0] instanceof TextFrame)) {

                alert("Please select some text");

                exit();

                }

       else {

            //shows the color in text

            for(var i = 0; i < app.selection.length; i++) {

 

 

            alert(ddl.selection.index);

            alert(ddl.selection);

        }

 

 

       }

   }

        

     //close button

    closeBtn.onClick = function() {

            w.close();

    }

 

 

     w.show();

     w.center();


'Object Invalid' when trying to remove() a pageItem

$
0
0

Hi,

 

I'm successfully getting a reference to a non-threaded text frame that I want to delete, but calling .remove() on it results in error 45 'Object is invalid'

 

Seems like this code should work? But it doesn't :-(

 

 

 

varworkbooklegal = workbook.pages.item(1).pageItems.item('govcapost-legal');

 


   // alert(workbooklegal) // InDesign alert: [Object PageItem]


   workbooklegal.remove();

Converting all hyperlinks to footnotes or endnotes

$
0
0

Hi everyone, I figured there would already be a script out there that would accomplish this, but can anyone point me in the right direction on converting all hyperlinks in a document into either footnotes or endnotes? For example, for a digital version of a book, there is lots of hyperlinked text items throughout. If this book were to be converted into a print version, the hyperlinked text's hyperlinks would not be available and you'd have to individually extract out each hyperlink, insert a footnote/endnote and then paste the hyperlink into the footnote/endnote area. This is very tedious. A script seems like the obvious solution. Any ideas? Thanks!

Convert specific text Variable to text through all pages

$
0
0

Hi, i want to convert every text variable named "Header" to text.

But when i run this code, it converts all text variables to text.

var myDoc = app.activeDocument;            for (i = 0, l = myDoc.pages.length; i < l; i++) {              page = myDoc.pages[i];           page.pageItems.everyItem().textVariableInstances.everyItem("Header").convertToText();     }      

 

Thank you all.

Create swatch from Pantone name

$
0
0

I thought it was possible for a script to create a new swatch from a Pantone name. For example, given the name 'PANTONE 7696 C' I can (manually) create a new swatch in the Swatches panel, in the Colour Mode dropdown select 'PANTONE+ Solid Coated', then enter '7696' in the entry field. When I click OK the swatch is added to the panel.

 

How do I do this with a script?

 

Thanks,

 

P.

[ID-CS5][JS] Pasting into a rectangle at same position

$
0
0

Hi,

 

I am trying to make a script and have been successful to a point...

 

I have content on a layer labeled "copy-layer"

Also, rectangles and polygons marking areas of copy-layer on another layer called "export-layer"

I want to copy all of the content from copy-layer inot each individual shape from  export-layer

This will help me export selection(i.e. individual shape) to JPEG.

 

I struggling to pasteinto() theses shapes and locate copied content at same position as it was on copy-layer.

 

Any help will be appreciated.

 

Thank You

 

 

johnD

Adding 1 pt. black border with a script

$
0
0

Hi guys,

 

I've recently found a script which will help my workflow tremendously if i can adjust it properly. I make obituaries for a living, which need a simple 1 pt black border around the whole page. I would like to have a script which adds this for me.

 

Currently I have this:

 

var myDoc = app.activeDocument;  

myDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin; 

var currentPage = myDoc.layoutWindows[0].activePage; 

var myLayer = app.activeDocument.layers.item("QR"); 

if(!myLayer.isValid) 

        myLayer = app.activeDocument.layers.add ({name: "kader"}); 

    } 

myLayer.layerColor = UIColors.GRASS_GREEN; 

myLayer.move(LocationOptions.AT_BEGINNING);  // üste tasi 

var myFrame = currentPage.rectangles.add ({geometricBounds:[0,0,85,200]}); 

myFrame.contentType = ContentType.GRAPHIC_TYPE; 

myFrame.appliedObjectStyle = krkod; 

myFrame.frameFittingOptions.autoFit = true; 

myFrame.itemLayer = myLayer; 

 

 

But this script doesn't take in account the varying size of the page. It only places it at the top left corner. Is there a way to make it that it will fit neatly around my whole page?
Also, it would be perfect if it would add the black border by it self. Can someone help me with this?

 

Kind regards!

Position of an library asset on the page – how to get it?

$
0
0

First of all, I would like to thank very much all the participants in the previous thread that I started a few days ago. I wasn't sure where to write the answer with thanks, so unfortunately I didn't write anything.... It was not nice. I'm sorry. Your solutions and discussions were very impressive and helpful. Thank you again !

 

Today I'm asking for help in understanding:

– where Indesign?/document?/library?/asset? keeps the information about position values of the library asset on page which is used by placeAsset() method?

– how to get the values or setnew values to placeAsset()

– is it possible to set position ( or maybe annother properties ) of placed library asset by script?

 

Than you for any suggestion or solution

a.


Looping through swatches for a dropdown in Indesign

$
0
0

Hey there,

 

I am having trouble getting my swatches to appear in my scriptUI panel. what I am looking for is a loop that cycles through the document to find all the swatches then lists them in a dropdown list as the CMYK value. I would eventually like to fill the whole length of the text with that color in the future, but I will start with this and work to that.

 

I did find a forum on here that does this but has the swatch color next to it. That was to much code for my liking so I'm looking at something easier to control.

Here is what I have so far.

 

 

var w = new Window("dialog", "See Your Swatches!", undefined);

     var panel = w.add("panel", undefined, "Swatches");

     panel.orientation = "row";

 

 

    //UI design

     var ddl = panel.add("dropdownlist");

     var colorSelectBtn = panel.add("button", undefined, "SELECT");

     var closeBtn = panel.add("button", undefined, "CLOSE");

  

    //variables

    var activeDoc = app.activeDocument;

    var swatches = activeDoc.swatches;

 

    //loop through the swatches

    for(var i = 0; i <= swatches.length; i++) {

        var mySwatches = swatches[i].name;

         

        //adds to dropdown

        ddl.add(mySwatches[i]);

    }

 

    ddl.selection= 0; //dropdown list swatch index

 

 

//swatch selected

colorSelectBtn.onClick = function() {

        alert(ddl.selection[i]);

   }

  

  

     //close button

    closeBtn.onClick = function() {

            w.close();

    }

 

     w.show();

     w.center();

  

 

 

I know im doing something wrong, but can't figure it out. I will add checks in later for selecting items but need this first.

 

Any ideas?

Diff b/w inline and anchored object and script to find them

$
0
0

hi ..

I see in the forum there are inline objects and anchored object, can someone explain what's the difference between them?

Are they the same?

if not, is there a way to create script to find an anchored but not inline object?

 

Thank you so much..

dropdown list background color change

$
0
0

Hey there,

 

i am working on a dropdown list to show my swatches in order on a panel. I would like each index color to have the background color of that number listed.

I am looking all over and struggling to find background colors of dropdown list. is this possible?

 

here is my code thus far.

 

 

 

 

#targetengine "session"; //not needed in Illustrator / After Effects

 

 

var w = new Window("dialog", "Swatches!", undefined);

     var panel = w.add("panel", undefined, "Swatches");

     panel.orientation = "row";

 

 

    //UI design

     var ddl = panel.add("dropdownlist"); 

     var colorSelectBtn = panel.add("button", undefined, "SELECT");

     var closeBtn = panel.add("button", undefined, "CLOSE");

    

    //variables

    var activeDoc = app.activeDocument;

    var swatches = activeDoc.swatches;

   

    //loop through the swatches

    for(var i = 0; i < swatches.length; i++) {

        //indexing swatches

        var mySwatches = swatches[i].name;

        //adds to dropdown

        ddl.add("item", mySwatches);

    }

 

 

     ddl.selection= 0; //dropdown list  first swatch index

 

 

    //swatch selected

    colorSelectBtn.onClick = function() {

       

       if (!(app.selection[0] instanceof TextFrame)) {

                alert("Please select some text");

                exit();

                }

       else {

            //shows the color in text

            for(var i = 0; i < app.selection.length; i++) {

 

 

            alert(ddl.selection.index);

            alert(ddl.selection);

        }

 

 

       }

   }

        

     //close button

    closeBtn.onClick = function() {

            w.close();

    }

 

 

     w.show();

     w.center();

push index number from javascript to jsx

$
0
0

Hey there,

 

I have my dropdown list woking from the HTML to javascript. once I select the dropdown that I want, I have an alert to tell me which index I selected from that array. The alert will be deleted when I have this working, but I cannot get this to be pushed to jsx.

 

javascript:

//textcolor button

var textColorBtn = document.querySelector("#textColorbtn");

textColorBtn.addEventListener("click", textColor);

function textColor() {

    selectedSwatchIndex();

    csInterface.evalScript("textColor()");

}

 

function selectedSwatchIndex(value) {

//grabs the data in dropdown html selected

var getSelectedValue = document.getElementById("swatchNumber");

//finds what index the data is

var selectedSwatch = getSelectedValue.options[getSelectedValue.selectedIndex].value;

alert(selectedSwatch);

}

 

 

my jsx:

function textColorSelection() {

   

    //loop through the text frames

    if (!(app.selection[0] instanceof TextFrame)) {

        alert("Please select a text frame");

        exit();

    } else {

          

    var myDoc = app.activeDocument;

    var myColors = myDoc.colors;

    var swatches = myDoc.swatches;

 

    //variable to hold swatches

    var dropDown = []; //set up empty swatch array

 

    //loop through all swatches in document

    for (var s = 0; s < swatches.length; s++) {

        var mySwatches = swatches[s].name;

//      adds to dropdown list

        dropDown.push(mySwatches);

    }

          

//    alert(dropDown);

    dropDown = 7; //swatch index

    var dropDownSelect = [swatches[dropDown].name]; //properties

           

    var colorSelect = String(dropDownSelect) 

       

//    alert(colorSelect);

 

    for(var i = 0; i < app.selection.length; i++) {

        app.selection[i].texts.everyItem().fillColor = colorSelect;

//        app.selection[i].texts.everyItem().fillColor = "Black";

    }

  }

}

 

 

right now I am adding the index of seven just to see some sort of swatch color add to my text frames.

anyone have any ideas on how to push the index from the javascript to jsx?

Indesign script for removing pages with specific content/keyword...

Viewing all 15932 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>