• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to use script to activate the document in the first place?

New Here ,
Mar 12, 2017 Mar 12, 2017

Copy link to clipboard

Copied

Please see the image as below, you can see 3 documents ("Document-1.indd", "Document-2.indd" and "Document-3.indd") are opened. "Document-3.indd" is now being activated. How to use script to activate the document in the first place (in this case, "Document-1.indd")?

Note: the name of the documents are changing.

TMP_DON

TOPICS
Scripting

Views

5.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 13, 2017 Mar 13, 2017

Hi aa,

did you try the solution in reply 5 and 6 ?

If there is no floating window and no-one moved tabs around, e.g. dragged a tab to a different position, the snippet in reply 5 should work. If that's not what you are after or if it is not working I see no way with ExtendScript (JavaScript) to solve this "problem".

If you already know the name of a document you want to make the active one or if you know, that the one you like to make the active one was opened as the n-th of all open documents, the

...

Votes

Translate

Translate
Guru ,
Mar 12, 2017 Mar 12, 2017

Copy link to clipboard

Copied

Interesting question,

I highly doubt you can do that with extendScript. Remember also that a window can be detached from the dock.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2017 Mar 13, 2017

Copy link to clipboard

Copied

Trevor×…  wrote

Interesting question,

I highly doubt you can do that with extendScript. Remember also that a window can be detached from the dock.

Hi Trevor,

hm. How did you interpreted the OP's question?
I cannot tell what's asked here.

Opening a document? => app.open(File("path"+"/"+"name.indd"))
Setting the active document? => app.activeDocument = app.documents.itemByName("Name")


Getting? or Setting the order of opened tabs according to the open documents names from left to right?

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 13, 2017 Mar 13, 2017

Copy link to clipboard

Copied

Hi Uwe

Getting the order of the tabs

Trevor

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2017 Mar 13, 2017

Copy link to clipboard

Copied

Hi Trevor,

ah. Maybe something like the snippet below would help.
Did not test it very much.

var id = app.activeDocument.id;

var newDoc = app.documents.add();

var allOpenDocs = app.documents.everyItem().getElements();

app.activeDocument = newDoc;

for(var n=1;n<allOpenDocs.length;n++)

{

    $.writeln(n+"\t"+allOpenDocs.id+"\t"+allOpenDocs.name);

};

newDoc.close(SaveOptions.NO);

app.activeDocument = app.documents.itemByID(id);

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2017 Mar 13, 2017

Copy link to clipboard

Copied

To activate the first tab if there are no floating tabs would be:

app.activeDocument = allOpenDocs[allOpenDocs.length-1];

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2017 Mar 13, 2017

Copy link to clipboard

Copied

Tested a bit and I can see that my snippet is not working as expected, if you move some tabs around.
Also a problem, if there are some floating windows.


If you do closing and opening new documents, only, then it will do.

So Trevor is right:

One cannot predict the order of the tabs of open documents at any time during a session.

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 12, 2017 Mar 12, 2017

Copy link to clipboard

Copied

Please use JavaScript or VBScript to do so. And note that the initial activated document is also changing (the initial activated document can be "Document-1.indd", "Document-2.indd" or "Document-3.indd").

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 13, 2017 Mar 13, 2017

Copy link to clipboard

Copied

Please ignore the situation of a window being detached from the dock. Then in this case, there is no floating window. Please use JavaScript or VBScript to activate the first tab.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2017 Mar 13, 2017

Copy link to clipboard

Copied

Hi aa,

did you try the solution in reply 5 and 6 ?

If there is no floating window and no-one moved tabs around, e.g. dragged a tab to a different position, the snippet in reply 5 should work. If that's not what you are after or if it is not working I see no way with ExtendScript (JavaScript) to solve this "problem".

If you already know the name of a document you want to make the active one or if you know, that the one you like to make the active one was opened as the n-th of all open documents, then you could get it by its name or by its ID-number (after sorting ID numbers).

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

Thank you for your message.

I have tested the solution in reply 5 and 6.

For the solution in reply 5, I found the ID of the open document is also changing.

For the solution in reply 6, it just activate the next tab.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

LATEST

Hi,

the ID number of an open document should never change during a session.
Session is the period between a launch and a quit action with InDesign.

Every document you open or add (and close—not saving to disk) is getting a new ID number higher than the one before.
As long as the document is open, the ID will not change. If you close and reopen the document a new ID number is issued.

What constantly is changing is the index number if you change the active document in a row of open documents.

The active document's index number ( not the id number ! ) is always 0 .

My snippets in reply 5 and 6 ( in combination ) try to do a snapshot-in-time. Nothing more. Nothing less.
If you close and open documents after doing the snapshot you first have to redo a new snapshot before you can tell what the order of tabs is.

And no-one should have moved tabs around with the mouse or opened a free-floating window.

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines