B4Print.com

Applications => Adobe InDesign => Topic started by: wonderings on July 09, 2020, 12:01:30 PM

Title: making a script for Indesign?
Post by: wonderings on July 09, 2020, 12:01:30 PM
When hunting around for a solution to make life a bit easier with a specific job I came across someone who wrote a script that should do exactly what I need. The problem is I have no idea how to make this script into a .jsx file that will work in Indesign.

I am using the latest version of Indesign CC on a Mac running Mojave.

I copied and pasted the info from the website into textedit. I then saved as an RTF as txt is not an option. I then changed the extension to .jsx and put it in the appropriate folder. Indesign shows it but it is greyed out. I am assuming I have done something wrong here. Is there a correct way I should be making a .jsx file on a Mac that will work with Indesign?

This is the script I want:

(function () {
var curDoc = app.activeDocument,
allPages = curDoc.pages,
nPages = allPages.length,
curPage,
i,p,
newMaster = curDoc.masterSpreads.itemByName("B-Masterpage");

for (i = nPages-1; i >= 0; i--) {
curPage = allPages;
p = curDoc.pages.add({appliedMaster: newMaster});
p.move(LocationOptions.AFTER, curPage);
}
}) ();
Title: Re: making a script for Indesign?
Post by: Joe on July 09, 2020, 12:30:00 PM
Open new document in text edit and convert to Plain Text as shown below. Then paste the text in and save using the .jsx extension and see if that works.
Title: Re: making a script for Indesign?
Post by: Joe on July 09, 2020, 12:38:01 PM
I tried it on my Mac and it does show up in the scripts lists and is not grayed out but if I run it I get this. No idea if there is something else that needs to be done to the text ===> .jsx process or what????
Title: Re: making a script for Indesign?
Post by: Joe on July 09, 2020, 12:41:05 PM
Formatting of the .jsx does not look like other .jsx files in the InDesign scripts folder. I suspect that is the problem. Your text looks like it may have been an Apple script of some sort.
Title: Re: making a script for Indesign?
Post by: DigiCorn on July 09, 2020, 11:08:39 PM
It also makes a difference which folder the script is placed in. I believe it needs to go into samples.
Title: Re: making a script for Indesign?
Post by: wonderings on July 10, 2020, 05:18:57 AM
I will try the convert to plain text and give that a shot. On the forum people said it worked, but obviously have not tried it myself. It is basically supposed to place a multipage PDF on every other page in Indesign.

I was putting the script in the "sample" section. I have a few scrips I copy over with each new version of Indesign and have put this one in the same spot.
Title: Re: making a script for Indesign?
Post by: Joe on July 10, 2020, 07:27:51 AM
I placed the .jsx script in the folder:

Macintosh HD⁩ ▸ ⁨Applications⁩ ▸ ⁨Adobe InDesign 2020⁩ ▸ ⁨Scripts⁩ ▸ ⁨Scripts Panel⁩ ▸ ⁨Samples⁩ ▸ ⁨JavaScript⁩

which is the correct folder but still got the error above.
Title: Re: making a script for Indesign?
Post by: Joe on July 10, 2020, 07:39:59 AM
Using the method to create a .jsx file above I made a new text file and added the code:

alert('Hello, world.');

And saved as hello.jsx and placed that in the InDesign scripts folder at:

Macintosh HD⁩ ▸ ⁨Applications⁩ ▸ ⁨Adobe InDesign 2020⁩ ▸ ⁨Scripts⁩ ▸ ⁨Scripts Panel⁩ ▸ ⁨Samples⁩ ▸ ⁨JavaScript⁩

And then ran it from within Indesign and it did pop up the message below.

So it does work so there must be an issue with the code in the first post. When you copied and pasted into the forum is it displaying the same it is was when you found the code. When posting on the forum you should enclose the text inside the code brackets so it displays correctly such as the example below:

alert('Hello, world.');
Title: Re: making a script for Indesign?
Post by: Mikie on July 10, 2020, 08:27:25 AM
See if this does what you need. Best I could tell you want to add a new page at the end of the document, based on master B. The script had the name of the master page as B-Masterpage, but without renaming the master page it is actually B-Master. Let me know if it isn't what you need and I can probably tweak it for you.

---
dostuff();
function dostuff(){
    var curDoc = app.activeDocument,
    allPages = curDoc.pages,
    nPages = allPages.length;
    newMaster = curDoc.masterSpreads.itemByName("B-Master");
    for (i = nPages-1; i >= 0; i--) {
        curPage = allPages;
        p = curDoc.pages.add({appliedMaster: newMaster});
        //~ p.move(LocationOptions.AFTER, END);
        }
    }
---