Article View: adobe.photoshop.scripting
Article #86Re: Action that resizes images by title that end in "_1" only
From: Paul_R
Date: Fri, 03 Apr 2009 18:46
Date: Fri, 03 Apr 2009 18:46
185 lines
4876 bytes
4876 bytes
This should be close...
function main(){
var dlg=
"dialog{text:'Script Interface',bounds:[100,100,500,410],"+
"panel0:Panel{bounds:[10,10,390,300] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"title:StaticText{bounds:[70,10,320,40] , text:'Resize Tif, Convert to JPG' ,properties:{scrolling:undefined,multiline:undefined}},"+
"panel1:Panel{bounds:[10,50,370,120] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"statictext1:StaticText{bounds:[10,10,130,27] , text:'Source Folder' ,properties:{scrolling:undefined,multiline:undefined}},"+
"source:EditText{bounds:[10,40,350,60] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"browse1:Button{bounds:[240,10,340,30] , text:'Browse' }},"+
"panel2:Panel{bounds:[10,130,370,200] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"statictext2:StaticText{bounds:[10,10,111,27] , text:'Output Folder' ,properties:{scrolling:undefined,multiline:undefined}},"+
"browse2:Button{bounds:[240,10,340,30] , text:'Browse' },"+
"output:EditText{bounds:[10,40,350,60] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}}},"+
"panel3:Panel{bounds:[10,210,370,250] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"statictext3:StaticText{bounds:[10,10,180,30] , text:'Output JPG Quality' ,properties:{scrolling:undefined,multiline:undefined}},"+
"quality:DropDownList{bounds:[250,10,336,30]}},"+
"button2:Button{bounds:[10,260,180,281] , text:'Ok' },"+
"button3:Button{bounds:[200,260,370,281] , text:'Cancel' }}};"
var win = new Window(dlg,'Resize TIFs');
win.center();
if(version.substr(0,version.indexOf('.'))>9){
win.panel0.title.graphics.font = ScriptUI.newFont("Times","BOLDITALIC",16);
}
win.panel0.panel1.source.enabled=false;
win.panel0.panel2.output.enabled=false;
win.panel0.panel1.browse1.onClick = function() {
inputFolder = Folder.selectDialog("Please select the folder with Files to process");
if(inputFolder !=null){
win.panel0.panel1.source.text = decodeURI(inputFolder.fsName);
}
}
win.panel0.panel2.browse2.onClick = function() {
outputFolder = Folder.selectDialog("Please select the output folder");
if(outputFolder !=null){
win.panel0.panel2.output.text = decodeURI(outputFolder.fsName);
}
}
for(var a = 1;a <13;a++){
win.panel0.panel3.quality.add('item',a);
}
win.panel0.panel3.quality.selection=7;
var done = false;
while (!done) {
var x = win.show();
if (x == 0 || x == 2) {
win.canceled = true;
//Cancelled
done = true;
} else if (x == 1) {
done = true;
var result = valiDate();
if(result != true) {
alert(result);
return;
}else
{
ProcessFolder();
}
}
}
function valiDate(){
if(win.panel0.panel1.source.text == '') return 'No Source Folder selected';
if(win.panel0.panel2.output.text == '') return 'No Output Folder selected';
return true;
}
function ProcessFolder(){
var fileList = inputFolder.getFiles("*.tif");
for (var a =0;a<fileList.length;a++){
var file = fileList[a];
var fileName = fileList[a].name.match(/(.*)\.[^\.]+$/)[1];
if(fileName.match(/_1$/)){
open(file);
activeDocument.resizeImage( 175, undefined, undefined, ResampleMethod.BICUBICSHARPER );
var saveFile= new File(outputFolder+"/"+fileName+".jpg");
SaveJPEG(saveFile, parseInt(win.panel0.panel3.quality.selection.index+1));
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
}
}
}
main();
function SaveJPEG(saveFile, jpegQuality){
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality; //1-12
activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
}
Technical Details
Message-ID:
<59b88070.1@webcrossing.la2eafNXanI>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!newshub.sdsu.edu!webcrossingReferences:
<59b88070.-1@webcrossing.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Thread: f5839,3321182ad52e9894 X-Google-Attributes: gidf5839,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: Paul_R@adobeforums.com Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!newshub.sdsu.edu!webcrossing Newsgroups: adobe.photoshop.scripting Subject: Re: Action that resizes images by title that end in "_1" only Message-ID: <59b88070.1@webcrossing.la2eafNXanI> Date: Fri, 3 Apr 2009 11:46:25 -0700 References: <59b88070.-1@webcrossing.la2eafNXanI> Lines: 113 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit