🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #73

Re: [CS3 JS] event crashes InDesign

#73
From: Kasyan_Servetsky
Date: Fri, 27 Mar 2009 17:33
88 lines
7179 bytes
Hi Rasmus,

Here is an example of scripted plug-in — very simple yet useful for me.
Its goal is to check color settings in InDesign and Photoshop after a document opens. We use two profiles at work: one for the main part of our magazine and another profile for its cover and the inset for another magazine. Sometimes, although rarely, we forget to switch on the correct setting.
That's where the plug-in comes to the aid. After a document opens it checks if the file name contains certain characters – e.g. if file name starts with "Obl_" that means that this is a cover and the script checks the color settings, if they are not correct it gives warning.

Here is short description of how to do it:
Create a new scripted plug-in project from APIDTemplate.indd file.
Open APID panel
Enter 'docLoaded' into Event Filter field and press Enter
Here is the script that does the job (the script file is generated in the same folder as indd-file):


 
if (theItem.eventCode == "docLoaded") {
   var gKasmyDoc = app.activeDocument;
   var gKasDocumentName = app.activeDocument.name;
   KasCheckProfile();
   KasinfoFromPS();
}

function KasCheckProfile(){

   var myIssueNumber = parseInt(gKasDocumentName.substr(2, 3));
   if (gKasDocumentName.substr(0, 2) == "Q_" && myIssueNumber >= 730 && myIssueNumber <= 999 && gKasDocumentName.match("_Vshivka") == null){
      if (app.colorSettings.workingSpaceCMYK != "ISO Web Coated"){
         alert("&#1042;&#1085;&#1080;&#1084;&#1072;&#1085;&#1080;&#1077;! &#1044;&#1083;&#1103; &#1075;&#1072;&#1079;&#1077;&#1090;&#1099; &#1076;&#1086;&#1083;&#1078;&#1077;&#1085; &#1080;&#1089;&#1087;&#1086;&#1083;&#1100;&#1079;&#1086;&#1074;&#1072;&#1090;&#1100;&#1089;&#1103; &#1087;&#1088;&#1086;&#1074;&#1080;&#1083;&#1100; \"ISO Web Coated\", &#1072; &#1091;&#1089;&#1090;&#1072;&#1085;&#1086;&#1074;&#1083;&#1077;&#1085;. &#8212; " + app.colorSettings.workingSpaceCMYK);
      }
   }
   if (gKasDocumentName.substr(0, 2) == "Q_" && myIssueNumber >= 730 && myIssueNumber <= 999 && gKasDocumentName.match("_Vshivka") != null){
      if (app.colorSettings.workingSpaceCMYK != "ImationMatchprn175lpi_avr.icc          "){
         alert("&#1042;&#1085;&#1080;&#1084;&#1072;&#1085;&#1080;&#1077;! &#1044;&#1083;&#1103; &#1074;&#1096;&#1080;&#1074;&#1082;&#1080; &#1076;&#1086;&#1083;&#1078;&#1077;&#1085; &#1080;&#1089;&#1087;&#1086;&#1083;&#1100;&#1079;&#1086;&#1074;&#1072;&#1090;&#1100;&#1089;&#1103; &#1087;&#1088;&#1086;&#1074;&#1080;&#1083;&#1100; \"ImationMatchprn175lpi_avr.icc\", &#1072; &#1091;&#1089;&#1090;&#1072;&#1085;&#1086;&#1074;&#1083;&#1077;&#1085;. &#8212; " + app.colorSettings.workingSpaceCMYK);
      }
   }
   else if (gKasDocumentName.substr(0, 4) == "Obl_"){
      if (app.colorSettings.workingSpaceCMYK != "ImationMatchprn175lpi_avr.icc          "){
//         alert("&#1042;&#1085;&#1080;&#1084;&#1072;&#1085;&#1080;&#1077;! &#1044;&#1083;&#1103; &#1086;&#1073;&#1083;&#1086;&#1078;&#1082;&#1080; &#1076;&#1086;&#1083;&#1078;&#1077;&#1085; &#1080;&#1089;&#1087;&#1086;&#1083;&#1100;&#1079;&#1086;&#1074;&#1072;&#1090;&#1100;&#1089;&#1103; &#1087;&#1088;&#1086;&#1074;&#1080;&#1083;&#1100; \"ImationMatchprn175lpi_avr.icc\", &#1072; &#1091;&#1089;&#1090;&#1072;&#1085;&#1086;&#1074;&#1083;&#1077;&#1085;. &#8212; " + app.colorSettings.workingSpaceCMYK);
         if (confirm("&#1042;&#1085;&#1080;&#1084;&#1072;&#1085;&#1080;&#1077;! &#1044;&#1083;&#1103; &#1086;&#1073;&#1083;&#1086;&#1078;&#1082;&#1080; &#1076;&#1086;&#1083;&#1078;&#1077;&#1085; &#1080;&#1089;&#1087;&#1086;&#1083;&#1100;&#1079;&#1086;&#1074;&#1072;&#1090;&#1100;&#1089;&#1103; &#1087;&#1088;&#1086;&#1074;&#1080;&#1083;&#1100; \"ImationMatchprn175lpi_avr.icc\", &#1072; &#1091;&#1089;&#1090;&#1072;&#1085;&#1086;&#1074;&#1083;&#1077;&#1085;. &#8212; " + app.colorSettings.workingSpaceCMYK)) {
            app.colorSettings.cmsSettings = "Listovaya Mashina";
         }
      }
   }  
}

function KasinfoFromPS() {
   var bt = new BridgeTalk;
   bt.target = "photoshop";
   bt.body = "app.colorSettings;"
   bt.onResult = function(resObj) {
      var myResult = resObj.body;
      KascheckPsColorSettings(myResult);
   }
   bt.send();
}

function KascheckPsColorSettings(myColorSettings){
   var myIssueNumber = parseInt(gKasDocumentName.substr(2, 3));
   if (gKasDocumentName.substr(0, 2) == "Q_" && myIssueNumber >= 730 && myIssueNumber <= 999 && gKasDocumentName.match("_Vshivka") == null){
      if (myColorSettings != "ISO Web Coated"){
         alert("&#1042;&#1085;&#1080;&#1084;&#1072;&#1085;&#1080;&#1077; &#1074; Photoshop! &#1044;&#1083;&#1103; &#1075;&#1072;&#1079;&#1077;&#1090;&#1099; &#1076;&#1086;&#1083;&#1078;&#1077;&#1085; &#1080;&#1089;&#1087;&#1086;&#1083;&#1100;&#1079;&#1086;&#1074;&#1072;&#1090;&#1100;&#1089;&#1103; &#1087;&#1088;&#1086;&#1074;&#1080;&#1083;&#1100; \"ISO Web Coated\", &#1072; &#1091;&#1089;&#1090;&#1072;&#1085;&#1086;&#1074;&#1083;&#1077;&#1085;. &#8212; \"" + myColorSettings + "\"");
      }
   }
   if (gKasDocumentName.substr(0, 2) == "Q_" && myIssueNumber >= 730 && myIssueNumber <= 999 && gKasDocumentName.match("_Vshivka") != null){
      if (myColorSettings != "Listovaya Mashina"){
         alert("&#1042;&#1085;&#1080;&#1084;&#1072;&#1085;&#1080;&#1077; &#1074; Photoshop! &#1044;&#1083;&#1103; &#1074;&#1096;&#1080;&#1074;&#1082;&#1080; &#1076;&#1086;&#1083;&#1078;&#1077;&#1085; &#1080;&#1089;&#1087;&#1086;&#1083;&#1100;&#1079;&#1086;&#1074;&#1072;&#1090;&#1100;&#1089;&#1103; &#1087;&#1088;&#1086;&#1074;&#1080;&#1083;&#1100; \"ImationMatchprn175lpi_avr.icc\", &#1072; &#1091;&#1089;&#1090;&#1072;&#1085;&#1086;&#1074;&#1083;&#1077;&#1085;. &#8212; \"" + myColorSettings + "\"");
      }
   }
   else if (gKasDocumentName.substr(0, 4) == "Obl_"){
      if (myColorSettings != "Listovaya Mashina"){
         alert("&#1042;&#1085;&#1080;&#1084;&#1072;&#1085;&#1080;&#1077; &#1074; Photoshop! &#1044;&#1083;&#1103; &#1086;&#1073;&#1083;&#1086;&#1078;&#1082;&#1080; &#1076;&#1086;&#1083;&#1078;&#1077;&#1085; &#1080;&#1089;&#1087;&#1086;&#1083;&#1100;&#1079;&#1086;&#1074;&#1072;&#1090;&#1100;&#1089;&#1103; &#1087;&#1088;&#1086;&#1074;&#1080;&#1083;&#1100; \"ImationMatchprn175lpi_avr.icc\", &#1072; &#1091;&#1089;&#1090;&#1072;&#1085;&#1086;&#1074;&#1083;&#1077;&#1085;. &#8212; \"" + myColorSettings + "\"");
      }
   }  
}



You can put your own stuff into the script:


if (theItem.eventCode == "docLoaded") {
// do your stuff here
}



And finally generate the plug-in.

Kasyan
Technical Details
Message-ID: <59b86a93.2@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!news2.glorb.com!newshub.sdsu.edu!webcrossing
References: <59b86a93.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,d51bfd07ae7dff66
X-Google-Attributes: gidf939a,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Kasyan_Servetsky@adobeforums.com
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!news2.glorb.com!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.scripting.indesign
Subject: Re: [CS3 JS] event crashes InDesign
Message-ID: <59b86a93.2@webcrossing.la2eafNXanI>
Date: Fri, 27 Mar 2009 10:33:28 -0700
References: <59b86a93.-1@webcrossing.la2eafNXanI>
Lines: 125
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit