Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

Adding a New Menu option in Indesign and running a script once clicked.

Community Beginner ,
Apr 23, 2018 Apr 23, 2018

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

TOPICS
Scripting
4.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Apr 27, 2018 Apr 27, 2018

Hi Rahul,

Please add the following statement at top of your script

#targetengine "session"

Translate
Contributor ,
Apr 26, 2018 Apr 26, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 26, 2018 Apr 26, 2018

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.Screen Shot 2018-04-26 at 16.24.22.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 26, 2018 Apr 26, 2018

Hello Rahul,

Please see my updated comment. You can ad menu by that script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 27, 2018 Apr 27, 2018

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); Screen Shot 2018-04-27 at 08.32.30.png

Hope you can assist with this code. Many thanks for helping.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 27, 2018 Apr 27, 2018

Hi Rahul,

Please add the following statement at top of your script

#targetengine "session"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 27, 2018 Apr 27, 2018
LATEST

Thanks very much for your help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2018 Apr 26, 2018

Have you read this article in Indiscripts article about this?

Indiscripts :: How to Create your Own InDesign Menus

Colin

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines