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

Hiding indesign while a script is working

Explorer ,
Aug 26, 2020 Aug 26, 2020

Copy link to clipboard

Copied

Hi everyone,

 

I'm working on many scripts that manipulate a lot of tables, which indesign struggles to process even with a powerful mac. I was wondering if there's a way in javascript to tell indesign to hide itself just before lauching the script commands? And if it's not possible, tell javascript to activate a shortcut (command + H to hide indesign) if possible?

 

All the best,

Nicolas

TOPICS
Scripting

Views

698

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

Explorer , Aug 26, 2020 Aug 26, 2020

Indeed, that does not work on mac os, but I found two solutions I want to share with you.

 

The first one :

the "restore()" method behave like app.activate() should.

// Hide InDesign
app.windows.everyItem().minimize();

// Script code goes here

// Show InDesign again
app.windows.everyItem().restore();

The second one is more complicated but it appears to be faster than the first one :

// Hide InDesign
var doc = app.activeDocument;
var _frames = doc.textFrames.everyItem().getElements();
var _bounds = [
...

Votes

Translate

Translate
Community Expert ,
Aug 26, 2020 Aug 26, 2020

Copy link to clipboard

Copied

What purpose do you want to solve by hiding InDesign? If the idea is to save the processing time by avoiding the UI updation, then try to open the file without a view(window). The app.open method has an argument that can be set to open the document without creating a window for it. This should speed up your processing

Varies open (from:Array of Varies File Files., [showingWindow:Boolean=Boolean], [openOption:OpenOptions=OpenOptions])

Opens the specified document, book, or library.

Parameter

Type

Description

from

File

Array of Files.

The file path(s) to the document, book, or library. Can accept: File or Array of Files.

showingWindow

Boolean

If true, opens the document in a window. If false, the document is opened but is not displayed in a window. (Optional)

(default: true)

openOption

OpenOptions

OpenOptions.DEFAULT_VALUE

OpenOptions.OPEN_COPY

OpenOptions.OPEN_ORIGINAL

How to open the document. (Optional)

(default: OpenOptions.DEFAULT_VALUE)

-Manan

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 ,
Aug 26, 2020 Aug 26, 2020

Copy link to clipboard

Copied

Manan's suggestion is probably the best way, but you have to open the document with your script and the script should save it. Then open the document in the interface to see the result.

To run a script against an open document and hide InDesign, use this code:

// Hide InDesign
app.windows.everyItem().minimize();

// Script code goes here

// Show InDesign again
app.activate();

Peter 

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
Explorer ,
Aug 26, 2020 Aug 26, 2020

Copy link to clipboard

Copied

Hello,

 

Thanks to both of you.

@Manan Joshi:

I didn't know this feature and this is definitely something I will use in the future, but for my script, to detail a little more what it does… for example I have to lower a table row which has line above and below the cells, so I need to increave the bottom inset of each cells in the previous row. but in some cases, I have to increase the topInset of every cells of my current row, it "graphickely" depends. I have another script that adds leftIndent of X mm to a selected text (in texteframe or in a cell). Tipically this one is really quick on a textframe but can take 10 seconds if the text within cells in a big table (tipically I have some documents of about 120 pages and between 80 to 100 tables, some are small, other really big).

 

The script must manipulate a selection, so I need to have the document opened and the content selected before I run the script.

 

@Peter Kahrel:

Your suggestion is almost perfect, the first line that minimises the document allows me to add a leftIndent instantly. without it, it takes about 6 to 7 seconds (don't know why it could vary). Unfortunately, "app.activate()" does not reactivate the document which staies in my dock. Is it an accessebility preference issue or anything like that?

 

Anyway, thanks again to both of you, I love this community.

Nicolas

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 ,
Aug 26, 2020 Aug 26, 2020

Copy link to clipboard

Copied

It worls for me on Windows. Maybe on a Mac this one, which is in fact more intuitive, works on the Mac (it doesn't on Windows):

 

app.windows.everyItem().maximize();

 

P.

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
Explorer ,
Aug 26, 2020 Aug 26, 2020

Copy link to clipboard

Copied

Indeed, that does not work on mac os, but I found two solutions I want to share with you.

 

The first one :

the "restore()" method behave like app.activate() should.

// Hide InDesign
app.windows.everyItem().minimize();

// Script code goes here

// Show InDesign again
app.windows.everyItem().restore();

The second one is more complicated but it appears to be faster than the first one :

// Hide InDesign
var doc = app.activeDocument;
var _frames = doc.textFrames.everyItem().getElements();
var _bounds = [];
for(var i = 0; i<_frames.length;i++){
   _bounds[i] = _frames[i].geometricBounds;    
}
doc.textFrames.everyItem().geometricBounds = ["0p", "0p", "0.1p", "0.1p"];

// Script code goes here

// Show InDesign again
for(var i = 0; i<_frames.length;i++){
   _frames[i].geometricBounds = _bounds[i];
}

This one change the height and weight of every text boxes to 0 and once the script is finished, it puts back the originals values.

 

Nicolas

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 ,
Aug 26, 2020 Aug 26, 2020

Copy link to clipboard

Copied

If .restore() works for you, use that. That other solution simply squeezes all the content out of all text frames causing them to become overset.That's brutal and it won't always work. For example, you can't refer to geometry, such as baseline, geometricBounds, horizontalOffset, etc.

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
Explorer ,
Aug 26, 2020 Aug 26, 2020

Copy link to clipboard

Copied

LATEST

Oh, ok I see the problem, I'll do more tests for the second solution and will use the first one for more safety.

Thanks again Peter, have a nice day.

 

Nicolas

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 ,
Aug 26, 2020 Aug 26, 2020

Copy link to clipboard

Copied

Hi Nicolas,

What I understood from your transcript, is that your current script workflow depends upon selection and hence my idea might not work. But there is no need to make the code work on selections, I mean if you have some other way to identify the object like the table in your case then better is to use that to get a reference to the object. For ex:- if it's to be done for all the tables you could iterate the tables collection, you should be easily able to identify the condition that would work for you.

-Manan

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
Explorer ,
Aug 26, 2020 Aug 26, 2020

Copy link to clipboard

Copied

Hey Manan,

 

Unfortunately, it is often a request from a client to make some exceptions, I can't automatize it for those types of examples. But I have other scripts that works as you suggested and will be much faster with the method you gave me in your first post 🙂

 

Nicolas

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 ,
Aug 26, 2020 Aug 26, 2020

Copy link to clipboard

Copied

No worries, i was just bouncing ideas around. Anyhow Peter has come with another input that might help.

-Manan

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