Copy link to clipboard
Copied
Hi All Me again. Sorry.
I'm trying to add a script to indesign - nothing seems to be working and I'm no good at code.
The name I want to call the menu is EXPORT PDF
and the script which finally works is:
d = app.activeDocument;
// Here you can choose the PDF preset
preset1 = app.pdfExportPresets.item ('Print1');
preset2 = app.pdfExportPresets.item ('Lowres');
if (!(preset1.isValid && preset2.isValid)){
alert("One of the presets does not exist. Please check spelling carefully.");
exit();
}
if (d.saved){
thePath = String(d.fullName).replace(/\..+$/, "") + ".pdf";
thePath = String(new File(thePath).saveDlg());
}
else{
thePath = String((new File).saveDlg());
}
thePath = thePath.replace(/\.pdf$/, "");
name1 = thePath + "LR.pdf";
name2 = thePath + "HR.pdf";
d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1);
d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);
Can anyone help with this. The PDF script is located in users but not sure about the beginning bit.
Many thanks
Rahul
Hi Rahul,
Please add the following statement at top of your script
#targetengine "session"
Copy link to clipboard
Copied
Hello Rahul, One option is you can add your script in Script panel.
For adding scripts in Script Panel
On MAC
Just go to the following location
/Applications/Adobe InDesign CC 2018/Scripts/Scripts Panel
and copy your script here. Open Indesign CC 2018, go to Windows -- > Utilities --> Scripts
You can see your script inside the panel. This will add the script inside Applications but if you want to add inside Users. You can check the following link
https://indesignsecrets.com/how-to-install-scripts-in-indesign.php
Adding menu
Here are the following steps to add menu PDF EXPORT
1. Write a new script with the following content and save file with addMenu.js (or whatever you want)
#targetengine "session"
var mySampleScriptAction = app.scriptMenuActions.add("Run Script");
var myEventListener = mySampleScriptAction.eventListeners.add("onInvoke", function() {
alert("This menu item was added by a script.");
// Add your script code here for exporting the PDF, that you have shared above
});
try {
var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.item("PDF EXPORT");
mySampleScriptMenu.title;
} catch (myError) {
var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.add("PDF EXPORT");
}
var mySampleScriptMenuItem = mySampleScriptMenu.menuItems.add(mySampleScriptAction);
2. Copy this file at the startup script of Indesign Application. On mac path for startup script is /Applications/Adobe InDesign CC 2018/Scripts/startup scripts
This path is based on which application version you are using.
3. Launch Indesign Application, if you put in Indesign CC 2018 then launch this application.
4. See the top menu, you will have a menu with name "PDF EXPORT" and inside this menu, you will have a submenu with the name "Run Script". When you click on this, your script will get executed. For reference please see screenshot
Hope this script will help you to execute your script from Menu
Copy link to clipboard
Copied
Hiya - I've got the script working from the earlier post and I know how to put it in the script folder, however I'm after creating a menu button at the top of the Indesign bar, I've created one by accident see attached. (WPS scripts). I want to create one similar but called EXPORT PDF. Then when I click on it, it runs the script. Any help would be fantastic.
Copy link to clipboard
Copied
Hello Rahul,
Please see my updated comment. You can ad menu by that script.
Copy link to clipboard
Copied
Hiya - one small problem but almost there. Here is my script - PDF Export appears in the menu, Run script also - but then there is an error.
var mySampleScriptAction = app.scriptMenuActions.add("Run Script");
var myEventListener = mySampleScriptAction.eventListeners.add("onInvoke", function() {
alert("This menu item was added by a script.");
d = app.activeDocument;
// Here you can choose the PDF preset
preset1 = app.pdfExportPresets.item ('Print1');
preset2 = app.pdfExportPresets.item ('Lowres');
if (!(preset1.isValid && preset2.isValid)){
alert("One of the presets does not exist. Please check spelling carefully.");
exit();
}
if (d.saved){
thePath = String(d.fullName).replace(/\..+$/, "") + ".pdf";
thePath = String(new File(thePath).saveDlg());
}
else{
thePath = String((new File).saveDlg());
}
thePath = thePath.replace(/\.pdf$/, "");
name1 = thePath + "LR.pdf";
name2 = thePath + "HR.pdf";
d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1);
d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);
});
try {
var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.item("PDF EXPORT");
mySampleScriptMenu.title;
} catch (myError) {
var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.add("PDF EXPORT");
}
var mySampleScriptMenuItem = mySampleScriptMenu.menuItems.add(mySampleScriptAction); 
Hope you can assist with this code. Many thanks for helping.
Copy link to clipboard
Copied
Hi Rahul,
Please add the following statement at top of your script
#targetengine "session"
Copy link to clipboard
Copied
Thanks very much for your help!
Copy link to clipboard
Copied
Have you read this article in Indiscripts article about this?
Indiscripts :: How to Create your Own InDesign Menus
Colin
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more