Skip to main content
BEGINNER_X
Legend
November 24, 2012
Question

Doubt in Document in Template

  • November 24, 2012
  • 1 reply
  • 1002 views

Hi All,

I am the beginner. I am studying through "InDesignCS3_ScriptingGuide_JS".

In page no 13, there is script 'save a document as a template'

Below script i am not able to understand, Can anyone explain it breifly if you willing.

Lines are below.

var myFileName;

if(app.activeDocument.saved == true){

//Convert the file name to a string.

myFileName = app.activeDocument.fullName + "";

//If the file name contains the extension ".indd", change it to ".indt".

if(myFileName.indexOf(".indd")!=-1){

var myRegularExpression = /.indd/gi

myFileName = myFileName.replace(myRegularExpression, ".indt");

}

}

Thanks in advance for all you read my scripts.

Thanks

BEGINNER

This topic has been closed for replies.

1 reply

Vamitul
Legend
November 24, 2012

well..

the script is very well commented..

if(app.activeDocument.saved == true){

  • checks if the current active document is saved. This is important because "Unsaved documents have no full name".

myFileName = app.activeDocument.fullName + "";

  • the fullName property of a document object returns a File object. This line converts that File object to a string (-containing the full path including the file name). The implementation is a bit unorthodox (don't think you will find it in many JavaScript books), but it works. Another way of doing it is: myFileName = app.activeDocument.fullName.toString()

if(myFileName.indexOf(".indd")!=-1){

  • checks if the string previously obtained contains ".indd". the indexOf() method of the String object returns -1 if the search string is not found. The problem here (and in the next lines) is if the file name is somenthing like: "myStrangeFile.indd.modifiedByStupidUser.indt"
  • for the rest of the lines I direct you to any general JavaScript beginner tutorials/books. A good reference: http://www.javascriptkit.com/jsref/
BEGINNER_X
Legend
November 24, 2012

Thanks a lot vamitul....