Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Changing filename variable with javascript

Return to Member Forum

  • Author
    Posts
    • #1250586
      Brett Stone
      Participant

      I’m wanting to capture the current document name in two variables, then change the extension in one.
      What I’ve done thus far (snipped below) doesn’t succeed at changing the second variable.
      Commenting in the script below tells what I’m trying to do.
      Do you more experienced scripters see where I’m going astray?

      (one area I’m looking at in line 7, but haven’t been able to resolve, is should the replace include /indd$ instead of indd, and should the ps be in quotes?)

      // set both variables to active document name
      var myDocName1 = document.name;
      var myDocName2 = document.name;
      // confirm the two variables in a simple alert
      alert(“Test result 1 ” + myDocName1 + ” and ” + myDocName2);
      // change the variable to replace indd with ps. This will be used in a later
      // printFile = “/Seps to PDF/” + myDocName2;
      myDocName2.replace(‘indd’, ‘ps’);
      alert(“Test result 2 ” + myDocName1 + ” and ” + myDocName2);
      // current result is myDocName2 remains unchanged

    • #1250878
      Max Pinton
      Participant

      You want the results of the replace (it doesn’t replace in-place), so try:

      myDocName2 = myDocName1.replace(‘indd’, ‘ps’);

    • #1251558
      Brett Stone
      Participant

      Max, thank you!
      It was that easy?? Gee, I think I had tried that, but maybe it was twenty things /like/ that.
      –Brett

Viewing 2 reply threads
  • The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
Forum Ads