Copy link to clipboard
Copied
Hi, I have a question, I have created this script to launch different types of commands, I have created a function for each command, but I have not figured out how to get the button to launch it, It gives me the error that a modal window is open.
Script here
// Path file master
var masterManutenzionePath = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\00_Manuale d'uso\\File master-template\\0091M - [MANUTENZIONE] - NEW.indd";
var masterManutenzioneDPIPath = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\00_Manuale d'uso\\File master-template\\0091M - [MANUTENZIONE_DPI] - NEW.indd";
var masterLavaggio1Path = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\00_Manuale d'uso\\File master-template\\0093L - [LAVAGGIO 1 ZONA].indd";
var masterLavaggio2Path = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\00_Manuale d'uso\\File master-template\\0093L - [LAVAGGIO 2 ZONE].indd";
var masterPittogrammiPath = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\00_Manuale d'uso\\File master-template\\0103P - [PITTOGRAMMI].indd";
var masterMovinPath ="\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\00_Manuale d'uso\\File master-template\\0072M - [MOVIN].indd";
//-----
// File master
var ManutenzioneFile = File(masterManutenzionePath);
var ManutenzioneDPIFile = File(masterManutenzioneDPIPath);
var Lavaggio1File = File(masterLavaggio1Path);
var Lavaggio2File = File(masterLavaggio2Path);
var PittogrammiFile = File(masterPittogrammiPath);
var MovinFile = File(masterMovinPath);
//-----
// Path file
var ManutenzionePath = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\30_File UTM\\Manutenzione programmata\\test";
var ManutenzioneDPIPath = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\30_File UTM\\Manutenzione programmata";
var Lavaggio1Path = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\30_File UTM\\Lavaggio";
var Lavaggio2Path = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\30_File UTM\\Lavaggio";
var PittogrammiPath = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\30_File UTM\Pittogrammi";
var MovinPath ="\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\30_File UTM\Movin";
//-----
// File manutenzione DPI
var filesManutenzioneDPI = "0091M - iM2.indd";
//-----
// File lavaggio 1 zona
var filesLavaggio1Zona = [
"0093L4 - Specola.indd",
"0093L4 - Sistema centraggio bottiglia.indd",
"0093L4 - Sistema centraggio bottiglia - AA.indd",
"0093L4 - Presenza metalli.indd",
"0093L4 - Espulsore Z200.indd",
"0093L4 - Espulsore soffio.indd",
"0093L4 - Espulsore push.indd",
"0093L4 - Espulsore push Z100_MOD.indd",
"0093L3 - Moduli rilevamento.indd",
"0093L3 - Controllo in macchina IE.indd",
"0093L3 - Controllo in macchina CL.indd",
"0093L3 - Controllo in macchina CE.indd",
"0093L1 - Quadro elettrico 700.indd",
"0093L1 - Quadro elettrico 600.indd"
]
//-----
// File lavaggio 2 zone da non modificare automaticamente
var fileLavaggio2Zone = [
"0093L2 - TB2000 + RX.indd",
"0093L2 - TB2000.indd"
]
//-----
// Funzioni
function ManutenzioneMaster(){
var myFolder = Folder(ManutenzionePath);
if (myFolder != null) {
var myFiles = [];
myFiles = myFolder.getFiles("*.indd");
for (var i = 0; i < myFiles.length; i++) {
var myFile = myFiles[i];
app.open(myFile);
}
}
for(var e = 0; e < app.documents.length; e++){
var documento = app.documents[e];
if (documento.name !== filesManutenzioneDPI){
documento.loadMasters(masterManutenzionePath, GlobalClashResolutionStrategyForMasterPage.LOAD_ALL_WITH_OVERWRITE);
}
else {
documento.loadMasters(masterManutenzioneDPIPath, GlobalClashResolutionStrategyForMasterPage.LOAD_ALL_WITH_OVERWRITE);
}
}
var documentiDaChiudere = [];
for (var c = 0; c < app.documents.length; c++) {
var documentoAperto = app.documents[c];
var nomeFile = documentoAperto.name;
documentoAperto.save();
documentiDaChiudere.push(documentoAperto);
}
for (var j = 0; j < documentiDaChiudere.length; j++) {
var documentoDaChiudere = documentiDaChiudere[j];
documentoDaChiudere.close(SaveOptions.NO);
}
}
// DIALOG
// ======
var dialog = new Window("dialog");
dialog.text = "Pagine principali V1.0";
dialog.preferredSize.width = 134;
dialog.orientation = "column";
dialog.alignChildren = ["center","top"];
dialog.spacing = 10;
dialog.margins = 16;
var Movin = dialog.add("button", undefined, undefined, {name: "Movin"});
Movin.text = "Movin";
//Movin.onClick = function(){
//dialog.close();
//}
var Manutenzione = dialog.add("button", undefined, undefined, {name: "Manutenzione"});
Manutenzione.text = "Manutenzione";
Manutenzione.onClick = function(){
dialog.close();
//ManutenzioneMaster();
}
dialog.show();
// ======
Copy link to clipboard
Copied
Maybe when you open files, InDesign shows a window about missing links or missing fonts. Try suppressing warnings when you open documents:
// Suppress errrors and warnings
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
// Open a document
// Then enable warnings
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
Copy link to clipboard
Copied
Hi peter, thanks to reply, the error is: MODAL DIALOG OR ALERT IS ACTIVE. the problem is that it does not execute the function because there is still the active window
// Path file master
var masterManutenzionePath = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\00_Manuale d'uso\\File master-template\\0091M - [MANUTENZIONE] - NEW.indd";
var masterManutenzioneDPIPath = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\00_Manuale d'uso\\File master-template\\0091M - [MANUTENZIONE_DPI] - NEW.indd";
var masterLavaggio1Path = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\00_Manuale d'uso\\File master-template\\0093L - [LAVAGGIO 1 ZONA].indd";
var masterLavaggio2Path = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\00_Manuale d'uso\\File master-template\\0093L - [LAVAGGIO 2 ZONE].indd";
var masterPittogrammiPath = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\00_Manuale d'uso\\File master-template\\0103P - [PITTOGRAMMI].indd";
var masterMovinPath ="\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\00_Manuale d'uso\\File master-template\\0072M - [MOVIN].indd";
//-----
// File master
var ManutenzioneFile = File(masterManutenzionePath);
var ManutenzioneDPIFile = File(masterManutenzioneDPIPath);
var Lavaggio1File = File(masterLavaggio1Path);
var Lavaggio2File = File(masterLavaggio2Path);
var PittogrammiFile = File(masterPittogrammiPath);
var MovinFile = File(masterMovinPath);
//-----
// Path file
var ManutenzionePath = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\30_File UTM\\Manutenzione programmata\\test";
var ManutenzioneDPIPath = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\30_File UTM\\Manutenzione programmata";
var Lavaggio1Path = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\30_File UTM\\Lavaggio";
var Lavaggio2Path = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\30_File UTM\\Lavaggio";
var PittogrammiPath = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\30_File UTM\Pittogrammi";
var MovinPath ="\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\30_File UTM\Movin";
//-----
// File manutenzione DPI
var filesManutenzioneDPI = "0091M - iM2.indd";
//-----
// File lavaggio 1 zona
var filesLavaggio1Zona = [
"0093L4 - Specola.indd",
"0093L4 - Sistema centraggio bottiglia.indd",
"0093L4 - Sistema centraggio bottiglia - AA.indd",
"0093L4 - Presenza metalli.indd",
"0093L4 - Espulsore Z200.indd",
"0093L4 - Espulsore soffio.indd",
"0093L4 - Espulsore push.indd",
"0093L4 - Espulsore push Z100_MOD.indd",
"0093L3 - Moduli rilevamento.indd",
"0093L3 - Controllo in macchina IE.indd",
"0093L3 - Controllo in macchina CL.indd",
"0093L3 - Controllo in macchina CE.indd",
"0093L1 - Quadro elettrico 700.indd",
"0093L1 - Quadro elettrico 600.indd"
]
//-----
// File lavaggio 2 zone da non modificare automaticamente
var fileLavaggio2Zone = [
"0093L2 - TB2000 + RX.indd",
"0093L2 - TB2000.indd"
]
//-----
// Funzioni
function ManutenzioneMaster(){
var myFolder = Folder(ManutenzionePath);
if (myFolder != null) {
var myFiles = [];
myFiles = myFolder.getFiles("*.indd");
for (var i = 0; i < myFiles.length; i++) {
var myFile = myFiles[i];
app.open(myFile);
}
}
for(var e = 0; e < app.documents.length; e++){
var documento = app.documents[e];
if (documento.name !== filesManutenzioneDPI){
documento.loadMasters(masterManutenzionePath, GlobalClashResolutionStrategyForMasterPage.LOAD_ALL_WITH_OVERWRITE);
}
else {
documento.loadMasters(masterManutenzioneDPIPath, GlobalClashResolutionStrategyForMasterPage.LOAD_ALL_WITH_OVERWRITE);
}
}
var documentiDaChiudere = [];
for (var c = 0; c < app.documents.length; c++) {
var documentoAperto = app.documents[c];
var nomeFile = documentoAperto.name;
documentoAperto.save();
documentiDaChiudere.push(documentoAperto);
}
for (var j = 0; j < documentiDaChiudere.length; j++) {
var documentoDaChiudere = documentiDaChiudere[j];
documentoDaChiudere.close(SaveOptions.NO);
}
}
// DIALOG
// ======
var dialog = new Window("dialog");
dialog.text = "Pagine principali V1.0";
dialog.preferredSize.width = 134;
dialog.orientation = "column";
dialog.alignChildren = ["center","top"];
dialog.spacing = 10;
dialog.margins = 16;
var Movin = dialog.add("button", undefined, undefined, {name: "Movin"});
Movin.text = "Movin";
//Movin.onClick = function(){
//dialog.close();
//}
var Manutenzione = dialog.add("button", undefined, undefined, {name: "Manutenzione"});
Manutenzione.text = "Manutenzione";
Manutenzione.onClick = function(){
dialog.close(2);
ManutenzioneMaster();
}
var Manutenzione_DPI = dialog.add("button", undefined, undefined, {name: "Manutenzione_DPI"});
Manutenzione_DPI.text = "Manutenzione DPI";
//Manutenzione_DPI.onClick = function(){
//dialog.close();
//}
var Lavaggio_1 = dialog.add("button", undefined, undefined, {name: "Lavaggio_1"});
Lavaggio_1.text = "Lavaggio 1 zona";
//Lavaggio_1.onClick = function(){
//dialog.close();
//}
var Lavaggio_2 = dialog.add("button", undefined, undefined, {name: "Lavaggio_2"});
Lavaggio_2.text = "Lavaggio 2 zone";
//Lavaggio_2.onClick = function(){
//dialog.close();
//}
var Pittogrammi = dialog.add("button", undefined, undefined, {name: "Pittogrammi"});
Pittogrammi.text = "Pittogrammi";
//Pittogrammi.onClick = function(){
//dialog.close();
//}
dialog.show();
// ======
Copy link to clipboard
Copied
Modal dialogs have the limitationt that InDesign performs only very few activities when they are open.
This is because real modal dialogs are supposed to support undo on cancel, preview checkbox and so forth.
With scripted modal dialogs, you can only fill in some variables from the matching dialog field, then close the dialog with the button and perform the actual activity.
Your direct alternative would be a modeless dialog which in ScriptUI goes by the keyword "palette" where you are using "dialog" above.
Another very new alternative would be a UXP Plugin with a palette window which is pretty close to native palettes of InDesign UI. This comes with other challenges (few proven code out in the wild for copy-paste) but is the new forthcoming technology, also you can to some degree reuse HTML web experiences.
Dirk
Copy link to clipboard
Copied
I modified the script with your suggestion, and found on the web the suggestion to insert in the first line: #targetengine 'foo'
now the script seems to work, but I wonder what's the point of inserting that wording
#targetengine 'foo'
// Path file master
var masterManutenzionePath = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\00_Manuale d'uso\\File master-template\\0091M - [MANUTENZIONE] - NEW.indd";
var masterManutenzioneDPIPath = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\00_Manuale d'uso\\File master-template\\0091M - [MANUTENZIONE_DPI] - NEW.indd";
var masterLavaggio1Path = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\00_Manuale d'uso\\File master-template\\0093L - [LAVAGGIO 1 ZONA].indd";
var masterLavaggio2Path = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\00_Manuale d'uso\\File master-template\\0093L - [LAVAGGIO 2 ZONE].indd";
var masterPittogrammiPath = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\00_Manuale d'uso\\File master-template\\0103P - [PITTOGRAMMI].indd";
var masterMovinPath ="\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\00_Manuale d'uso\\File master-template\\0072M - [MOVIN].indd";
//-----
// File master
var ManutenzioneFile = File(masterManutenzionePath);
var ManutenzioneDPIFile = File(masterManutenzioneDPIPath);
var Lavaggio1File = File(masterLavaggio1Path);
var Lavaggio2File = File(masterLavaggio2Path);
var PittogrammiFile = File(masterPittogrammiPath);
var MovinFile = File(masterMovinPath);
//-----
// Path file
var ManutenzionePath = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\30_File UTM\\Manutenzione programmata\\test";
var ManutenzioneDPIPath = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\30_File UTM\\Manutenzione programmata";
var Lavaggio1Path = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\30_File UTM\\Lavaggio";
var Lavaggio2Path = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\30_File UTM\\Lavaggio";
var PittogrammiPath = "\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\30_File UTM\Pittogrammi";
var MovinPath ="\\\\ftsystem.local\\root\\FTSystem-HQ\\UTDocs\\File standard\\30_File UTM\Movin";
//-----
// File manutenzione DPI
var filesManutenzioneDPI = "0091M - iM2.indd";
//-----
// File lavaggio 1 zona
var filesLavaggio1Zona = [
"0093L4 - Specola.indd",
"0093L4 - Sistema centraggio bottiglia.indd",
"0093L4 - Sistema centraggio bottiglia - AA.indd",
"0093L4 - Presenza metalli.indd",
"0093L4 - Espulsore Z200.indd",
"0093L4 - Espulsore soffio.indd",
"0093L4 - Espulsore push.indd",
"0093L4 - Espulsore push Z100_MOD.indd",
"0093L3 - Moduli rilevamento.indd",
"0093L3 - Controllo in macchina IE.indd",
"0093L3 - Controllo in macchina CL.indd",
"0093L3 - Controllo in macchina CE.indd",
"0093L1 - Quadro elettrico 700.indd",
"0093L1 - Quadro elettrico 600.indd"
]
//-----
// File lavaggio 2 zone da non modificare automaticamente
var fileLavaggio2Zone = [
"0093L2 - TB2000 + RX.indd",
"0093L2 - TB2000.indd"
]
//-----
// Funzioni
function ManutenzioneMaster(){
var myFolder = Folder(ManutenzionePath);
if (myFolder != null) {
var myFiles = [];
myFiles = myFolder.getFiles("*.indd");
for (var i = 0; i < myFiles.length; i++) {
var myFile = myFiles[i];
app.open(myFile);
}
}
for(var e = 0; e < app.documents.length; e++){
var documento = app.documents[e];
if (documento.name !== filesManutenzioneDPI){
documento.loadMasters(masterManutenzionePath, GlobalClashResolutionStrategyForMasterPage.LOAD_ALL_WITH_OVERWRITE);
}
else {
documento.loadMasters(masterManutenzioneDPIPath, GlobalClashResolutionStrategyForMasterPage.LOAD_ALL_WITH_OVERWRITE);
}
}
var documentiDaChiudere = [];
for (var c = 0; c < app.documents.length; c++) {
var documentoAperto = app.documents[c];
var nomeFile = documentoAperto.name;
documentoAperto.save();
documentiDaChiudere.push(documentoAperto);
}
for (var j = 0; j < documentiDaChiudere.length; j++) {
var documentoDaChiudere = documentiDaChiudere[j];
documentoDaChiudere.close(SaveOptions.NO);
}
}
// DIALOG
// ======
var dialog = new Window("palette");
dialog.text = "Pagine principali V1.0";
dialog.preferredSize.width = 134;
dialog.orientation = "column";
dialog.alignChildren = ["center","top"];
dialog.spacing = 10;
dialog.margins = 16;
var Movin = dialog.add("button", undefined, undefined, {name: "Movin"});
Movin.text = "Movin";
Movin.onClick = function(){
dialog.close();
}
var Manutenzione = dialog.add("button", undefined, undefined, {name: "Manutenzione"});
Manutenzione.text = "Manutenzione";
Manutenzione.onClick = function(){
ManutenzioneMaster()
dialog.close();
}
var Manutenzione_DPI = dialog.add("button", undefined, undefined, {name: "Manutenzione_DPI"});
Manutenzione_DPI.text = "Manutenzione DPI";
//Manutenzione_DPI.onClick = function(){
//dialog.close();
//}
var Lavaggio_1 = dialog.add("button", undefined, undefined, {name: "Lavaggio_1"});
Lavaggio_1.text = "Lavaggio 1 zona";
//Lavaggio_1.onClick = function(){
//dialog.close();
//}
var Lavaggio_2 = dialog.add("button", undefined, undefined, {name: "Lavaggio_2"});
Lavaggio_2.text = "Lavaggio 2 zone";
//Lavaggio_2.onClick = function(){
//dialog.close();
//}
var Pittogrammi = dialog.add("button", undefined, undefined, {name: "Pittogrammi"});
Pittogrammi.text = "Pittogrammi";
//Pittogrammi.onClick = function(){
//dialog.close();
//}
dialog.show();
// ======
//~ var dialogResult = dialog.show()
//~ if(dialogResult === 2){
//~ alert("manutenzione");
//~ //ManutenzioneMaster()
//~ } else if (dialogResult === 1){
//~ alert("movin");
//~ }
Copy link to clipboard
Copied
You can replace "foo" with your company name.
A targetengine is a separate, isolated execution environment. Own globals, own functions. Same as in a web browser where one page should not interfere with another page in the next browser tab.
Unlike the "main" default targetengine, all other target engines are not terminated after the run so your dialog can continue to refer to its functions and variables. You also have to consider that during development, functions and variables will still be around from the previous run - until Quit of InDesign.