making a script for Indesign?

Started by wonderings, July 09, 2020, 12:01:30 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

wonderings

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);
}
}) ();

Joe

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.
Mac OS Sonoma 14.2.1 (c) | (retired)

The seven ages of man: spills, drills, thrills, bills, ills, pills and wills.

Joe

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????
Mac OS Sonoma 14.2.1 (c) | (retired)

The seven ages of man: spills, drills, thrills, bills, ills, pills and wills.

Joe

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.
Mac OS Sonoma 14.2.1 (c) | (retired)

The seven ages of man: spills, drills, thrills, bills, ills, pills and wills.

DigiCorn

It also makes a difference which folder the script is placed in. I believe it needs to go into samples.
"There's been a lot of research recently on how hard it is to dislodge an impression once it's been implanted in someone's mind. (This is why political attack ads don't have to be true to be effective. The other side can point out their inaccuracies, but the voter's mind privileges the memory of the original accusation, which was juicier than any counterargument ever could be.)"
― Johnny Carson

"Selling my soul would be a lot easier if I could just find it."
– Nikki Sixx

"Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut."
― Ernest Hemingway

wonderings

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.

Joe

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.
Mac OS Sonoma 14.2.1 (c) | (retired)

The seven ages of man: spills, drills, thrills, bills, ills, pills and wills.

Joe

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.');
Mac OS Sonoma 14.2.1 (c) | (retired)

The seven ages of man: spills, drills, thrills, bills, ills, pills and wills.

Mikie

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);
        }
    }
---