🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.photoshop.scripting
Article #386

Re: Script EPS to TIFF

#386
From: christoph_pfaffenbichler
Date: Tue, 03 Mar 2009 09:37
159 lines
4694 bytes
This checks for eps� only by using the name, so if other files mistakenly are named �.eps� it probably would cause problems, and I haven�t provided a provision for avoiding over-writting existing tiffs of the same names, but You could give this a try:


 
#target photoshop; 

var dlg = new Window('dialog', "save flattened tiffs of eps-files", [500,300,880,525]); 

//filter for checking if entry is numeric, thanks to xbytor; 

numberKeystrokeFilter = function() { 

   this.text = this.text.replace(",", "."); 

   if (this.text.match(/[^\-\.\d]/)) { 

      this.text = this.text.replace(/[^\-\.\d]/g, ''); 

   } 

}; 

//create the entry for resolution; 

dlg.msgPnl = dlg.add('panel', [25,100,355,170], 'resolution'); 

dlg.msgPnl.msgEt = dlg.msgPnl.add('edittext', [15,20,135,40], 150, {multiline:false}); 

dlg.msgPnl.msgEt.onChange = numberKeystrokeFilter; 

//create a field for folder-selection; 

dlg.folderPnl = dlg.add('panel', [25,25,355,90]); 

dlg.folderPnl.btn = dlg.folderPnl.add('button', [12,7,313,17], 'select a folder to process', {name:'remove'}); 

dlg.folderPnl.folderName = dlg.folderPnl.add('statictext', [12,35,313,55], "none selected", {multiline:false}); 

// select a folder-function; 

function folderSelection (theFolder) { 

   var theFolder = Folder.selectDialog ("select a folder"); 

   dlg.folderPnl.folderName.text = String(theFolder); 

   }; 

dlg.folderPnl.btn.onClick = folderSelection; 

//fields for ok and cancel; 

dlg.buildBtn = dlg.add('button', [25,185,175,195], 'OK', {name:'ok'}); 

dlg.cancelBtn = dlg.add('button', [185,185,355,195], 'Cancel', {name:'cancel'}); 

// show dialog; 

var myReturn = dlg.show (); 

//////////// the operation ////////////////// 

if (myReturn == true && dlg.folderPnl.folderName.text != "none selected") { 

// retrieve file-list and resolution; 

var theFolder = dlg.folderPnl.folderName.text; 

var theFileList = Folder(theFolder).getFiles(); 

var theResolution = dlg.msgPnl.msgEt .text; 

// do the thing; 

for (var m = 0; m < theFileList.length; m++) { 

   // getting the name and location; 

   var docName = theFileList[m].name; 

   var docPath = theFileList[m].path; 

   var basename = docName.match(/(.*)\.[^\.]+$/)[1]; 

   // open only files whose names end on �.eps�; 

   if (docName.slice(-4) == ".eps") { 

      // ======================================================= 

      var idOpn = charIDToTypeID( "Opn " ); 

         var desc1 = new ActionDescriptor(); 

         var idnull = charIDToTypeID( "null" ); 

         desc1.putPath( idnull, new File( theFileList[m] ) ); 

         var idAs = charIDToTypeID( "As  " ); 

            var desc2 = new ActionDescriptor(); 

            var idRslt = charIDToTypeID( "Rslt" ); 

            var idRsl = charIDToTypeID( "#Rsl" ); 

            desc2.putUnitDouble( idRslt, idRsl, theResolution ); 

            var idAntA = charIDToTypeID( "AntA" ); 

            desc2.putBoolean( idAntA, true ); 

         var idEPSG = charIDToTypeID( "EPSG" ); 

         desc1.putObject( idAs, idEPSG, desc2 ); 

      executeAction( idOpn, desc1, DialogModes.NO ); 

      // define the copy: 

      var theCopy = app.activeDocument; 

      // tiff options; 

      tifOpts = new TiffSaveOptions(); 

      tifOpts.embedColorProfile = true; 

      tifOpts.imageCompression = TIFFEncoding.TIFFLZW; 

      tifOpts.alphaChannels = false; 

      tifOpts.byteOrder = ByteOrder.MACOS; 

      tifOpts.layers = false; 

      // make a copy, flatten it, delete paths, set it to 8bit; 

      theCopy.flatten(); 

      theCopy.bitsPerChannel = BitsPerChannelType.EIGHT; 

      // save it; 

      theCopy.saveAs((new File(docPath+"/"+basename+".tif")),tifOpts,true); 

      theCopy.close(SaveOptions.DONOTSAVECHANGES); 

      } 

   else {} 

   } 

}; 

// use it at your own risk;

If any of You spot unnecessary or stupid operations in the Script please let me know.
Technical Details
Message-ID: <59b81640.0@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!news2.glorb.com!newshub.sdsu.edu!webcrossing
References: <59b81640.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f5839,4e95cf668558441c
X-Google-Attributes: gidf5839,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII
From: christoph_pfaffenbichler@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.photoshop.scripting
Subject: Re: Script EPS to TIFF
Message-ID: <59b81640.0@webcrossing.la2eafNXanI>
Date: Tue, 3 Mar 2009 01:37:13 -0800
References: <59b81640.-1@webcrossing.la2eafNXanI>
Lines: 118
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit