[CS4/5][JS] Script causes InDesign to crash

Hello,
I'm having a bit of an issue with some InDesign scripting i'm working on, and wonder if anyone else has had the same issue.
I have a script that uses app.dialog to prompt for user information.  It then takes the result of that dialog, and uses it in the script.  Pretty standard so far, and if i run this from the scripts panel, or from ESTK, it works fine.  If I set it up as a Script Menu Action, when I run the script via the menu, it executes, then crashes InDesign.
I have tried this with multiple dialog's, and each time a dialog is called from a SMA, InDesign crashes.  The following code is fairly pointless, but will cause InDesign to crash when the SMA is run.
//failTest.jsx
//Test script will cause InDesign to crash when the SMA is invoked
//Daniel Cole
//Wed Jun 09 2010 13:26:47 GMT-0400
#targetengine "session"
//set up the SMA and eventListener
var saTest = app.scriptMenuActions.add("Test SMA");
var elTest = saTest.eventListeners.add("onInvoke", function()
          alert(testFunc());
//Check for the menu, and create it if it doesn't exist
try{
    var menuTest = app.menus.item("$ID/Main").submenus.item("Test");
    menuTest.title;
catch (e){
    var menuTest = app.menus.item("$ID/Main").submenus.add("Test");
menuTest.menuItems.add(saTest)
//test function
//creates a dialog box with a text edit box
//returns the content of the text edit box
function testFunc(){
     testDialog = app.dialogs.add({name:"Enter Text:", canCancel:true});
          with(testDialog){
               with(dialogColumns.add()){
                    var getTextField = textEditboxes.add({editContents: "Test Text", minWidth:250});
     testResult = testDialog.show()
     if(testResult == true){
          var testText = getTextField.editContents;
          testDialog.destroy();
          return testText;
     else{
          return "No Text Entered";
          myFileDialog.destroy();
I've tried this on CS4 and CS5, on multiple installs, and it crashes every time.  Can anyone else replicate this?  Is this a known issue?  Is there any way to work around it?
thanks,
Daniel Cole
Electronic Prepress and Automation Specialist
Disc Makers

I don't know exactly why your code crashes ID in some versions, but there are potential issues in using:
- unneeded global variables in a function scope,
- the with statement,
- the "var menuTest" redeclaration in the try...catch,
- a generic #targetengine "session" directive,
- menu and menuAction creation procedure without preventing object duplication (beware of application/session persistence),
- the myFileDialog.destroy() instruction when myFileDialog is unknown (in your original code).
In order to isolate the "destroy" bug, I suggest you separate the process from the menu installer (see http://bit.ly/cIsZuG for more detail about menu management).
Here is a possible structure:
#targetengine "DanielColeTest"
// YOUR PROCESS
// Use clean local vars within the func
var testFunc = function()
     var dlg = app.dialogs.add({
          name:"Enter Text:",
          canCancel:true
     var textField = dlg.dialogColumns.add().textEditboxes.add({
          editContents: "Test Text",
          minWidth:250
     var r = (dlg.show())?
          textField.editContents:
          "No Text Entered - Marc";
     dlg.destroy();
     return r;
var testInvokeHandler = function(/*onInvoke*/)
     alert( testFunc() );
// YOUR MENU INSTALLER
// Encapsulate the routine to avoid duplication issues
// - a SMA is session-persistent
// - a menu is application-persistent
var testInstaller = testInstaller||(function()
     var smaTitle = "Test SMA",
          mnuTitle = "Test",
          subs = app.menus.item("$ID/Main").submenus,
          sma, mnu;
     // 1. Create the script menu action
     sma = app.scriptMenuActions.add(smaTitle);
     // 2. Attach the onInvoke event handler
     sma.eventListeners.add("onInvoke",testInvokeHandler);
     // 3. Create and/or target the menu
     mnu = subs.item(mnuTitle);
     if( !mnu.isValid ) mnu = subs.add(mnuTitle);
     // 4. Create the menu item
     mnu.menuItems.add(sma);
     return true;
Hope it could help.
Regards,
Marc

Similar Messages

  • How do I fix problem causing Indesign to crash everytime I open it?

    I have had InDesign CC 2014 installed on windows 8 computer for month but recently I cannot open it as evertytime it crashed saying 'windows has encountered a problem causing InDesign to stop working' I have tried everything I can think of...please help! (I have it through creative cloud and my other programmes are fine so I don't understand why it is just InDesign?)

    What happened the last time it did work? Was there a crash? You might have bad recovery data that is causing it to crash again on restart.
    See Replace Your Preferences  for directions to the HIDDEN folders where your prefs are stored. The recovery folder is in the same location as the InDesign SavedData file. Empty it and try again.

  • GP login script causes windows to crash

    We have a script that runs on all computers that opens our intranet. This script crashed Windows build 9926 overtime. Is there any way to fix this. Also I can't install the new build because the HP printers update fails everytime.

    Hi,
    How did you determined that it is the script caused this problem? If this problem caused by the script indeed, what't the function of this script?
    For HP printer problem, it's probably a driver compatibility with new system problem, it would be better to contact HP support to confirm this issue.
    Roger Lu
    TechNet Community Support

  • Saving .idml causes InDesign 6 crash

    Working on a large book with multiple chapter files. The client has asked for .idml files. The whole book has gone smoothly with no software issues, but when I try to save any of the chapter files as .idml, InDesign 6 crashes almost immediately. I have restarted InDesign, restarted my Mac, now installed the latest version on InDesign 6. Still crashing. Any ideas?

    My fault entirely.
    When I tried to load the .idml file into BBEdit, I was using a lnk to an old, thrown-out BBEdit version, and that's what caused it.
    I thought the editor had opened the file, but it was just the system saying there was no editor.
    Thanks. All fixed.

  • My documents causes  indesign to crash

    i have been working on multiple documents and now indesign crashes when it opens some of them.. what could be causing this, i have reinstalled but the problem persists.

    I am guessing it is a font issue (especially if you are attempting to use PC fonts on a mac). I would take one of your corrupt documents and if you can open it for a minute, just enough time to change all of your fonts to something super standard like Trebuchet and save it as a copy/rename. then see if that one has any issues. If you cant even open them for long enoh to change the fonts, try temporarily removing the fonts (that you are using in these documents) from your system font folder (I like to temporarily place them in the trash so I know they are not accidentally being used anywhere. Maybe also  do a find on your os to make sure those fonts are not hiding somewhere on your system. Then restart your mac and indesign and see if thats it.
    If that is it, your fonts may be too old. I had this problem with fireworks except  FW wouldnt even stay open for a second before it crashed. Adobe told me it was because I had old fonts. This was not cool because A) they are my companies coporate fonts and B) They didnt cause any other CS4 app to crash. I made a big stink (and was probably a pretty big jerk to the innocent tech support guy) that the app would crash rather than give me a message that those fonts are not compatible etc etc, They told me I would have to return cs4 and get cs3 just to see if that would be a fix. I responded hell no as that is way too much of a hassle for the few times I may use fireworks and my company just has too much red tape to get that done. So I just simply gave up on learning fireworks. Then, one day I saw a FW update/patch, installed it and it worked. Maybe I was the guy who helped get that issue fixed. Next time ill fill out a bug report rather than yelling at some poor guy that im going to sue adobe. lol
    So if that is it, id make a bug report, If thats not it, i would try those documents on another computer/differnt versions of ID if possible. It also may be a photograph that is corrupt or possibly so large that your machine cant handle displaying it (16/32bit in pshop?). Or just see if you can replicate the crash one piece ata a time starting from a blank document. long answer yes, but i just like to hear myself type. hope that helps.

  • Damaged document causes InDesign to crash when opening.

    I have a short document that crashes InDesign everytime I open it. I have tried emptying the recovery data and using the dutch 'restore' script, but it still won't open.
    Are there any other options? I can send the document over if someone would be kind enough to check it to see if they can figure out the problem? Am on quite a tight deadline with this one (I literally had almost finished...) so any help would be appreciated.

    Hi , thanks for getting back to me, yes it was the :blindOpen_and IDML-Export script. I could run the script but when i assume when it 'blind-opened' the document there was a problem and InDesign stopped working.
    The document has 130pp. text and about 10 jpgs. scattered throughout. It was taken from a PDF export then inserted into InDesign. Images were placed normally.
    One strange thing - there was a lot of latin auto-fill text at the end of the document. When I went to delete this, the programme stopped working.

  • Damaged file causes InDesign to crash and I can not open it now?

    I was working on a document and tried to use the eye dropper tool to select a color for a box I was going to use.
    I accidentally clicked on a placed vector image box and the document closed and InDesign quit.
    After doing some searching online, it was recommended to find the recovery file and delete it from my system, however, I can't find exactly where it is.
    I wound up deleting several items from the cashe file, but that didn't work.
    I did an "uninstall" of InDesign and then installed a new version. That did not work either.
    Where I am now...I can open InDesign and create a new document, but every time I try to open either the damaged file or the previous year file (which should not be damaged), InDesign crashes.
    i.e. - The file that crashed was the 2015 version of my document. I went to archived versions of that particular document (2014 and also 2013 versions) and they all crashed.
    (The files were all named different, based on the year created).
    Help!

    Emptying the recovery folder makes sense to me....as far as the plugins, font manager, I'm not sure if that would be the problem.
    Of course, at this point, I'm striking out. I don't know how or what to do about plugins...do you have specific directions?
    Because of the deadline, I'm having to start over on my project. I think instead of building the pages in InDesign, I'll build in Photoshop and place the Photoshop files into InDesign.
    I can't remember ever having this problem and I've used InDesign for many years. I am on the monthly plan and have the latest versions of everything.

  • Transparent Tif from CS6 Droplet Causes Indesign to crash

    I created a droplet to create a transparent TIF out of my layered PSD file. When I place this image then in my Indesign document it crashes Indesign. When I manualy run the image through these steps in Photoshop of converting it to CMYK and saving the file as a TIF it works just fine. I even tryed creating the droplet of CS5 and the resulting image does not crash Indesign. So I was wondering if anyone else has run into this problem with CS6?

    Emptying the recovery folder makes sense to me....as far as the plugins, font manager, I'm not sure if that would be the problem.
    Of course, at this point, I'm striking out. I don't know how or what to do about plugins...do you have specific directions?
    Because of the deadline, I'm having to start over on my project. I think instead of building the pages in InDesign, I'll build in Photoshop and place the Photoshop files into InDesign.
    I can't remember ever having this problem and I've used InDesign for many years. I am on the monthly plan and have the latest versions of everything.

  • Image swap script causing crashes.

    I am writing a script that will randomly swap images between selected image frames. The script works fine (but it's still slow) on a smaller selection. But once the selection gets past 12/14 items it causes indesign to crash.
    any thoughts?
    thanks
    if (parseFloat(app.version) < 6) {
       main();
    } else {
       app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Swap Images");
    function main(){
       var mySelection = app.selection;
       if (!mySelection.length < 3)
          var framesArr = [];
          var imagesArr = [];
          for(var i = 0; i < mySelection.length; i++)
             if(mySelection[i].allGraphics.length && mySelection[i].allGraphics[0].itemLink.status == LinkStatus.NORMAL) {
                framesArr.push(mySelection[i]);
                imagesArr.push(mySelection[i].allGraphics[0].itemLink.filePath);
          randomizeLinks(framesArr, imagesArr);
       } else {
          alert("Please select three or more image frames");
    function randomizeLinks(framesArr, imagesArr)
       imagesArrRand = imagesArr.sort(randOrd);
       swapImages(framesArr, imagesArrRand);
    function randOrd()
       return (Math.round(Math.random())-0.5);
    function swapImages(frames, links)
          for(var j = 0; j < frames.length; j++)
                frames[j].allGraphics[0].remove();
    //~             $.writeln(frames[j] + " " + links[j] + "\r\r")
                frames[j].place(links[j]);

    Hi tusharde,
    AFAIK, ExtendScript does not support the use of Math.random() within an Array.sort(…) callback.
    The callback function must provide a stable order.
    @+
    Marc

  • JSX causing Indesign CC 2014 to Crash even when the execution is successful

    Hi,
    I have JSX which is executing successfull and returning a string value, but even after that indesign CC 2014 is getting crashed as soon as result is Returned from JSX.
    has any one faced such issue ???
    This issue is not there in Indesign CC 9.2 executing the same JSX.

    Finally after a lot of debugging I found the issue.
    In Indesign CC 2014, the handling for Hidden documents has been changed how it used to be for Indesign CC 9.2.
    Now we can not run command doc.Close() on a hidden document. This is what was causing Indesign to Crash.
    Also, app.documents no more contains the count of hidden documents. Only those documents are maintained for which layout is open.
    Not sure if such major API changes have been mentioned as a part of API changes doc.

  • InDesign Server crashing on hyperlinks - HYPERLINKS.RPLN

    When trying to access properties of a hyperlink it causes InDesign to crash. I can assign properties of the hyperlink but if I try and retrieve properties it hangs and crashes resulting in the error below. I'm using InDesign Server 64bit version 7.0.4.553. What's interesting is this works completely fine when testing using InDesign CS5 client version.
    I have used Extend script toolkit to try and debug the issue but you can't even use the databrowser to look at the hyperlink properties as it'll crash there as well. But if I debug using toolkit with client version of InDesign it works fine. It really seems like an issue with InDesign Server and I'm not sure what I can do to work around/fix this problem.
    Example script -
    var myDoc = app.open([document path]);
    for (i = 0; i < myDoc.hyperlinks.length; i++)
         var myHyperlink = myDoc.hyperlinks[i];  
         var newDestination = myHyperlink.destination; // - this causes indesign to crash
         //Do some processing...
    Faulting application name: InDesignServer.exe, version: 7.0.4.553, time stamp: 0x4d891c6d
    Faulting module name: HYPERLINKS.RPLN, version: 7.0.4.553, time stamp: 0x4d891ef9
    Exception code: 0xc0000005
    Fault offset: 0x000000000006e33b
    Faulting process id: 0x1dfc
    Faulting application start time: 0x01ccd52e23e3216c
    Faulting application path: C:\Program Files\Adobe\Adobe InDesign CS5 Server x64\InDesignServer.exe
    Faulting module path: C:\Program Files\Adobe\Adobe InDesign CS5 Server x64\Required\HYPERLINKS.RPLN
    Any help would be great! I can post more information if needed.

    I think I may have found the problem...
    It appears that the particular document I'm working with has a shared link that is contained in another document (in InDesign if you look at the hyperlink details it is a shared destination and for "document" it specifies a different document then the current one. This would probably happen when the hyperlink is copied from a different document. When trying to access that shared link it is unable to get the properties of it because there is actually no reference to it as the other document isn't open on the server.
    This is an interesting problem because I'm not sure where to go with this... I need to be able to get the hyperlink but with the given scenario I can't figure out a way to do that.

  • InDesign CS6 crashes when I try to copy a graphic

    I am working in CS6 with a document that was converted from CS4. I want to move a graphic from one spot in the document to another, but when I try to copy it, InDesign immediately crashes. Has anyone else had this problem?
    I am working on a PC, and I believe the original file was created on a Mac.

    It turns out the culprit was a bad font in the image. I opened the image in Illustrator and converted the font to outlines. That solved the problem! Incidentally, this one image/font problem (this image is used in a couple different manuals) also was causing InDesign to crash when I exported to PDF.
    Adobe people, if you read this, it would be great if problematic fonts in images were detected by InDesign, like an error in the preflight panel similar to the linking and font errors currently there. I can't see a way to detect this easily now (how to narrow down which image is a problem when working with 50+ images in a document?) Is there a way that I don't know about?

  • InDesign CS6 crashes when editing TOC

    I have an INDD C6 file with a TOC that I created for a print book. I am now making the eBook version of the file. I saved the print book file under a new name. Please note, this is a regular InDesign file (INDD) -- not a Book file (INDB).
    I am trying to edit the TOC style. I select "Layout" > "Table of Contents..." I change "Page Number" selection to "No Page Number". I click "Save Style" button. I give the style a new name. But when I click "OK" InDesign crashes. I have tried to make this simple edit countless times. I have quit out of InDesign and relaunched it. I have restarted my Mac. I even tried to manually delete the page numbers in the TOC but  that caused InDesign to crash as well.
    I have to have an unnumbered TOC for my eBook. Any suggestions on what to do?
    thanks,
    Lenora

    See Remove minor corruption by exporting
    And keep in mind that you can have multiple TOCs and TOC styles in the same file, so you could try making a completely new TOC.

  • InDesign keeps crashing on type tool/when multiple files are opened??

    I've 'trashed' my preferences, updated both Suitcase 3 and CS5 to the latest updates...and still having issues. Just constant crashing whenever I open multiple files, or as soon as I enter a text box to make edits.
    Here's my two crash reports:
    pastebin.com/Q3LeHAZ7
    http://pastebin.com/3pSxgUvN
    And a sample process:
    http://pastebin.com/DDCGyEG1
    Any advice would be greatly appreciated! Thanks!

    Hmm yes, I've just had my first crash of the day - tried to package a file and it froze when copying the font files over.
    Well, that does seem a plausible summary of what is happening. Your crash report is of particular interest, because it doesn't really implicate InDesign:
    Thread 34 Crashed:
    0   com.apple.CoreFoundation           0x91f6f65f _CFURLIsFileURL + 15
    1   com.apple.CoreFoundation           0x91fd2a80 CFURLSetResourcePropertiesForKeys + 32
    2   com.apple.DesktopServices          0x90bc6af0 TCopyWriter::WriteDates() + 990
    3   com.apple.DesktopServices          0x90bc639f TCopyWriter::WriteExtendedAttributes() + 357
    4   com.apple.DesktopServices          0x90bc00f3 TCopyWriter::Write() + 185
    5   com.apple.DesktopServices          0x90bbf9d5 TCopyWriter::WriteTaskProc(void*) + 75
    6   ...ple.CoreServices.CarbonCore     0x9294254a PrivateMPEntryPoint + 68
    7   libSystem.B.dylib                  0x90a06259 _pthread_start + 345
    8   libSystem.B.dylib                  0x90a060de thread_start + 34
    so, that is a crash in Apple code. Now, of course, the apple code was called from InDesign, and there's a certain degree of garbage-in-garbage-out. If you ask the operating system to copy a nonexistent file to a nonexistent device, it might crash. It shouldn't but it might.
    And if we look at thread 0, which is InDesign code, we can sort of see where InDesign invoked the operating system:
    Thread 0:  Main Thread  Dispatch queue: com.apple.main-thread
    0   libSystem.B.dylib                  0x90a06aa2 __semwait_signal + 10
    1   libSystem.B.dylib                  0x90a0675e _pthread_cond_wait + 1191
    2   libSystem.B.dylib                  0x90a083f8 pthread_cond_wait$UNIX2003 + 73
    3   ...ple.CoreServices.CarbonCore     0x9297721e TSWaitOnCondition + 126
    4   ...ple.CoreServices.CarbonCore     0x92962b68 TSWaitOnConditionTimedRelative + 202
    5   ...ple.CoreServices.CarbonCore     0x9295e533 MPWaitOnQueue + 250
    6   com.apple.DesktopServices          0x90bc730b TCopyQueue::WaitOnRecordDone() + 55
    7   com.apple.DesktopServices          0x90bc1287 TCopyReader::GetNextItem() + 875
    8   com.apple.DesktopServices          0x90bbfdf6 TCopyReader::Read(unsigned long long, TCountedPtr<TCFURLInfo> const&, TCountedPtr<TCFURLInfo> const&) + 164
    9   com.apple.DesktopServices          0x90bf64e3 TFSCopyOperation::CopyToTarget() + 613
    10  com.apple.DesktopServices          0x90bf9228 TFSCopyOperation::DoCopy(TCountedPtr<TCFURLInfo> const&) + 780
    11  com.apple.DesktopServices          0x90bf9898 TFSCopyOperation::Run() + 174
    12  com.apple.DesktopServices          0x90bee5e9 _NodeOperation + 438
    13  ...ple.CoreServices.CarbonCore     0x929c2090 _FSOperateOnObjectSync + 352
    14  ...ple.CoreServices.CarbonCore     0x929c228f _FSPathOperateOnObjectSync + 210
    15  AdobeAFL                           0x016e9101 adobe::afl::CoreFileUtils::CopyFile(adobe::afl::AFile const&, adobe::afl::AFile const&, bool) + 365
    16  PublicLib.dylib                    0x014339da FileLinkResourceHandler::CopyToFile(UIDRef const&, URI const&, IDFile&) const + 58
    17  com.adobe.InDesign.Links           0x21c54c4e 0x21bd8000 + 511054
    So, where does that leave us? Well, we would like to know what file is being copied, and why the file copy operation caused the operating system to crash the program.
    Are you sure it was a font? Could it have been copying another linked file?
    I don't suppose you have any folks around the office who know their way around Apple's Xcode tools, that are used for developing Objective C applications? There are some ways to figure out what file is causing InDesign to crash, but they're all kind of cryptic and annoying to explain without doing it in person...
    If not, let me know and I'll try to figure out a simple way to explain it... (and to figure out which of the cryptic tools are the best ones to recommend for this situation. A question that might take me some time to answer....)

  • Indesign CC crashes while using spellcheck - what to do?

    indesign CC crashes while using spellcheck - what to do?

    InDesign 2014.2 Release  |  10.2.0.69 Build
    I recently upgraded to the latest version of InDesign via the Cloud app and two chronic issues have reappeared:
    Text randomly disappears during editing on the page.
    Launching the spellcheck function causes InDesign to crash.
    Come on, Adobe — I (and many other users) dealt with these problems for months after we transitioned from CS6 to CC 2014. Eventually, you fixed the problems, but it took forever! Now they’re back with your latest “upgrade.”
    This is ridiculous!

Maybe you are looking for