Recent

Author Topic: making a script for Indesign?  (Read 869 times)

0 Members and 1 Guest are viewing this topic.

Offline wonderings

  • Sr. Member
  • ****
  • Posts: 383
making a script for Indesign?
« on: July 09, 2020, 02: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);
}
}) ();

Offline Joe

  • Master of Nothing
  • Administrator
  • Ninja Warlord
  • *****
  • Posts: 37710
  • Gender: Male
    • B4Print.com
Re: making a script for Indesign?
« Reply #1 on: July 09, 2020, 02: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.
Mac OS 10.14.6 Mojave | Prinergy 8.2 | Adobe Creative Cloud 2019 | Two Luscher XPose 160 CTP units

Prepress: One who does precision guess work based on unreliable data provided by those of questionable knowledge.

Offline Joe

  • Master of Nothing
  • Administrator
  • Ninja Warlord
  • *****
  • Posts: 37710
  • Gender: Male
    • B4Print.com
Re: making a script for Indesign?
« Reply #2 on: July 09, 2020, 02: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????
Mac OS 10.14.6 Mojave | Prinergy 8.2 | Adobe Creative Cloud 2019 | Two Luscher XPose 160 CTP units

Prepress: One who does precision guess work based on unreliable data provided by those of questionable knowledge.

Offline Joe

  • Master of Nothing
  • Administrator
  • Ninja Warlord
  • *****
  • Posts: 37710
  • Gender: Male
    • B4Print.com
Re: making a script for Indesign?
« Reply #3 on: July 09, 2020, 02: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.
Mac OS 10.14.6 Mojave | Prinergy 8.2 | Adobe Creative Cloud 2019 | Two Luscher XPose 160 CTP units

Prepress: One who does precision guess work based on unreliable data provided by those of questionable knowledge.

Offline DigiCorn

  • Terrorizing humans since 1971
  • Supreme Ninja
  • ***
  • Posts: 15496
  • Gender: Male
  • There is no Dana, only Zul!
    • Clerks.
Re: making a script for Indesign?
« Reply #4 on: July 10, 2020, 01:08:39 AM »
It also makes a difference which folder the script is placed in. I believe it needs to go into samples.
"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

Offline wonderings

  • Sr. Member
  • ****
  • Posts: 383
Re: making a script for Indesign?
« Reply #5 on: July 10, 2020, 07: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.

Offline Joe

  • Master of Nothing
  • Administrator
  • Ninja Warlord
  • *****
  • Posts: 37710
  • Gender: Male
    • B4Print.com
Re: making a script for Indesign?
« Reply #6 on: July 10, 2020, 09: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.
Mac OS 10.14.6 Mojave | Prinergy 8.2 | Adobe Creative Cloud 2019 | Two Luscher XPose 160 CTP units

Prepress: One who does precision guess work based on unreliable data provided by those of questionable knowledge.

Offline Joe

  • Master of Nothing
  • Administrator
  • Ninja Warlord
  • *****
  • Posts: 37710
  • Gender: Male
    • B4Print.com
Re: making a script for Indesign?
« Reply #7 on: July 10, 2020, 09:39:59 AM »
Using the method to create a .jsx file above I made a new text file and added the code:

Code: [Select]
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:

Code: [Select]
alert('Hello, world.');
Mac OS 10.14.6 Mojave | Prinergy 8.2 | Adobe Creative Cloud 2019 | Two Luscher XPose 160 CTP units

Prepress: One who does precision guess work based on unreliable data provided by those of questionable knowledge.

Offline Mikie

  • Sr. Member
  • ****
  • Posts: 315
  • Gender: Male
Re: making a script for Indesign?
« Reply #8 on: July 10, 2020, 10: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);
        }
    }
---