2011-01-14 12 views
5

Come posso avere il mio script .jsx al termine dell'esecuzione di un altro .jsx script?Script .jsx di Adobe InDesign script execute .jsx

Forse questo aiuterà a capire quello che sto cercando di fare:

// WebCard.jsx file 

function mySnippet(){ 
    //<fragment> 
    var myPageName, myFilePath, myFile; 
    var myDocument = app.documents.item(0); 
    var myBaseName = myDocument.name; 
    for(var myCounter = 0; myCounter < myDocument.pages.length; myCounter++){ 
     myPageName = myDocument.pages.item(myCounter).name; 
     app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange; 
     app.jpegExportPreferences.resolution = 96; 
     app.jpegExportPreferences.pageString = myPageName; 

      switch(myPageName) { 
     case "1" : myPageName = "EN FRONT WebCard"; 
      docType = "Web/Web Cards" break; 
     case "2" : myPageName = "EN BACK WebCard"; 
      docType = "Web/Web Cards" break; 
     case "3" : myPageName = "ES FRONT WebCard"; 
      docType = "Web/Web Cards" break; 
     case "4" : myPageName = "ES BACK WebCard"; 
      docType = "Web/Web Cards" break; 

    } 
     fileName = group + " " + myPageName + " " + date + ".jpg"; 

     myFilePath = dirPath + docType + "/" + fileName; 
     myDocument.exportFile(ExportFormat.jpg, File(myFilePath), false); 
    } 
    //</fragment> 
} 
//</snippet> 
       // execute PrintCard.jsx file 


//<teardown> 
function myTeardown(){ 
} 
//</teardown> 

Speranza che aiuta?

risposta

3

Ecco un frammento di alcuni ExtendScript che uso per avviare altri script; L'ho usato in After Effects, ma probabilmente funzionerà in InDesign, anche:

var theScriptFile = new File("/path/to/file.jsx"); 

var oldCurrentFolder = Folder.current; 
Folder.current = theScriptFile.parent; 

theScriptFile.open(); 
var theScriptContents = theScriptFile.read(); 
theScriptFile.close(); 

gCurrentScriptFile = theScriptFile; 

if(doDebug) 
    debugger; 

// You have entered the debugger in Launcher... 
// to debug the script you've launched, step 
// into the eval() function below. 
// 
eval("{" + theScriptContents + "}"); 

Folder.current = oldCurrentFolder; 
gCurrentScriptFile = ""; 

L'approccio è quello di leggere il file e eval esso. (PS un altro buon tag sarebbe ExtendScript, qui.) Vedi anche: http://omino.com/pixelblog/2007/11/15/binary-files-in-extendscript/

+0

Sto avendo un po 'di problemi a leggere, dove dovrei posizionare lo script che vorrei avviare (PrintCard.jsx)? – jmituzas

+0

var theScriptFile = new File ("/ absolute/path/to/PrintCard.jsx"); ma ... potresti aver bisogno del percorso assoluto ... le app di adobe potrebbero comportarsi diversamente sui percorsi relativi; dovrai sperimentare con InDesign per vedere se puoi fare un nuovo file ("../ PrintCard.jsx") o simili; se possibile, cerca di evitare il percorso assoluto che penso. –

+0

Hahaha avrei dovuto leggerlo di nuovo dato che hai dichiarato: nuovo file ("/ percorso/to/file.jsx"); - Mi dispiace per quello ... – jmituzas

5

Si può facilmente comprendere un altro script che verrà eseguito nel punto in cui si include:

// ... Do something (will be executed before teardown script) 


#include "../path/to/teardown/script.jsx" 
// the path can be absolute or relative. 

Questo dovrebbe funzionare in InDesign da CS3 verso l'alto.

+0

Funziona perfettamente per me! Grazie! – Syjin