Skip to main content
Participating Frequently
July 23, 2012
Answered

[JS]: Is there anyway to change a document's name?

  • July 23, 2012
  • 3 replies
  • 4290 views

Is there anyway to change a document's name? Or create a document with a certain name?

I'm looking at the JavaScript reference, and it says that document.name is a readonly value. Is this entirely true / is there any other way to change the name of a document?

Any help would be much appreciated

Thanks!

This topic has been closed for replies.
Correct answer Peter Kahrel

You can change the name of a document in two ways:

1. Open it, save it under a different name, and delete the original.

2. Don't open the document, use JavaScirpt's File object to rename the document. Details can be found in the JavaScript Tools Guide, accessed from your ESTK in the Help menu.

Peter

3 replies

Velprakash
Inspiring
July 24, 2012

Hi Alex,

  Use this...

myDocument = app.activeDocument;

path = myDocument.fullName;

alert(path);

var x = path.toString().replace("oldName", "NewName");  

//OldName is ur file's name. newName is the name u want to save it.

myDocument.save(File(x));

With Regards,

Vel.

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
July 23, 2012

You can change the name of a document in two ways:

1. Open it, save it under a different name, and delete the original.

2. Don't open the document, use JavaScirpt's File object to rename the document. Details can be found in the JavaScript Tools Guide, accessed from your ESTK in the Help menu.

Peter

Vamitul
Legend
July 23, 2012

app.documents.add ([showingWindow: bool=true][, documentPreset: DocumentPreset][, withProperties: Object])

the main interest for you is the "withProperties" part.


Participating Frequently
July 23, 2012

I'm new to javascript so bear with me :c

I don't fully understand the type Object. Since there is no specific reference for withProperties, I don't get how I would insert the parameters I need into a variable of the type "Object"

Is there somewhere I can see this?

Vamitul
Legend
July 23, 2012

ok.. my mistake. i just tried it and it doesn't work.

Apparently the ony way to chage the name of the document is by saving it with (another) filename

var d=app.documents.add(false);

d.save("d:\mytestdoc.indd");

alert(d.name);