4

I am new to InDesign scripting though I do have experience with Javascript. I created a new menu item as you will see in the script below, which I planned to use it to call another script onclick. However I am facing some issues, so I decided to delete the menu item and start over. But at line 10, I get the message "undefined is not an object", which I can't figure out why it's causing a problem.

Any help will be appreciated.

//#targetengine "ImportFolder"

//var myMainMenu = app.menus.item("Main");
//var myCustomMenu = myMainMenu.submenus.item("Import Folder");
//var myCustomMenu = myMainMenu.submenus.add("Import Folder");
//var mySampleScriptAction = app.scriptMenuActions.add("onInvoke", function() {
//app.doScript(new File ("/C/Program Files (x86)/Adobe/Adobe InDesign CS6/Scripts/Scripts Panel/importFiles.jsx" ));});

//delete the menu
var myMainMenu = app.menus.item("Main");
try{
var myCustomMenu = myMainMenu.submenus.item("Import Folder");
myCustomMenu.remove();
}catch(myError){}
Ria S.
  • 63
  • 1
  • 11
  • Which line is line 10? `var myMainMenu = app.menus.item("Main");`? – Kevin B Apr 03 '14 at 15:04
  • @KevinB: it should be, because the rest of this mini-script is protected against run-time errors with the `try..catch` construction. However ... purely theoretically, that line should not have failed; `alert (myMainMenu.submenus.everyItem().name);` works for me. – Jongware Apr 03 '14 at 15:13
  • This is not the only script that this is happening. On a second script I get the exact same message (undefined is not an object), on the very 1st line (var myDocument = app.documents.add();). – Ria S. Apr 03 '14 at 16:31

1 Answers1

7

Try re-installing Indesign. If the scripting library dll lost its registration, it could cause all of the scripts to fail.

...wait a minute - are you trying to use this script from the Extendscript Toolkit? If you are, you have to change engines.

Also, if you have more than one version of CS on your system, you need to make sure you use the Extendscript Toolkit that matches the version of your InDesign - in other words, EXTK CS6 for IND CS6.

enter image description here

Another thing to try is to remove the new from your doscript command. I like to wrap mine in a function like this:

//run a script from the CS6 Script Panel Directory (be sure to add the file extension
function RunMyScript(whatscriptname){
    app.doScript(File("/C/Program Files (x86)/Adobe/Adobe InDesign CS6/Scripts/Scripts Panel/" + whatscriptname));
}
bgmCoder
  • 6,205
  • 8
  • 58
  • 105
  • 2
    It appears it was the engine I had to change. I didn't know that. Thanks very much for your help! – Ria S. Apr 04 '14 at 15:00
  • Glad to help; It took me awhile to realize what the problem was. If you had mentioned ExtendScript Toolkit in your question then someone else would have figured it out. – bgmCoder Apr 04 '14 at 15:29
  • 1
    The engine part seems more likely. We had the same issue yesterday. Thanks to your answer, it was easy to fix. – Wolf Feb 01 '16 at 12:29