harvey |
05-21-2009 01:52 PM |
Code:
/*
<javascriptresource>
<name>Batch Save for Web</name>
<type>automate</type>
<about>Author Paul Riggott</about>
<category>aaaThisPutsMeAtTheTopOfTheMenu</category>
</javascriptresource>
*/
function main(){
var dlg =
"dialog{text:'Script Interface',bounds:[100,100,640,470],"+
"panel0:Panel{bounds:[10,10,530,360] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"title:StaticText{bounds:[90,20,470,50] , text:'CS2-CS3 Batch Save For Web' ,properties:{scrolling:undefined,multiline:undefined}},"+
"panel1:Panel{bounds:[10,60,510,190] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"Bridge:Checkbox{bounds:[10,10,250,30] , text:'Use Selected Bridge Files' },"+
"statictext1:StaticText{bounds:[10,40,120,60] , text:'Select Input Folder' ,properties:{scrolling:undefined,multiline:undefined}},"+
"Folder1:EditText{bounds:[140,40,390,60] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"Browse1:Button{bounds:[400,40,491,60] , text:'Browse' },"+
"statictext2:StaticText{bounds:[10,100,130,120] , text:'Select Output Folder' ,properties:{scrolling:undefined,multiline:undefined}},"+
"Folder2:EditText{bounds:[140,100,390,120] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"Browse2:Button{bounds:[400,100,491,120] , text:'Browse' },"+
"statictext4:StaticText{bounds:[10,70,111,90] , text:'Select File Type' ,properties:{scrolling:undefined,multiline:undefined}},"+
"fileType:DropDownList{bounds:[140,70,230,90]},"+
"statictext5:StaticText{bounds:[260,70,390,90] , text:'Select Output Quality' ,properties:{scrolling:undefined,multiline:undefined}},"+
"qual:DropDownList{bounds:[400,70,486,90]}},"+
"panel2:Panel{bounds:[10,200,510,290] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"ResizeCheck:Checkbox{bounds:[10,10,149,31] , text:'Resize To Fit' },"+
"WW:StaticText{bounds:[150,10,180,30] , text:'W:' ,properties:{scrolling:undefined,multiline:undefined}},"+
"Width:EditText{bounds:[180,10,230,30] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"PX1:StaticText{bounds:[230,10,260,30] , text:'px' ,properties:{scrolling:undefined,multiline:undefined}},"+
"HH:StaticText{bounds:[360,10,390,30] , text:'H:' ,properties:{scrolling:undefined,multiline:undefined}},"+
"Height:EditText{bounds:[390,10,440,30] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"PX2:StaticText{bounds:[440,10,470,30] , text:'px' ,properties:{scrolling:undefined,multiline:undefined}},"+
"Action:Checkbox{bounds:[10,60,119,81] , text:'Run Action' },"+
"ActionSet:DropDownList{bounds:[120,60,300,80]},"+
"ActionName:DropDownList{bounds:[310,60,490,80]}},"+
"panel3:Panel{bounds:[10,300,510,340] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"button2:Button{bounds:[10,10,240,31] , text:'Ok' },"+
"button3:Button{bounds:[260,10,490,31] , text:'Cancel' }}}}";
var win = new Window(dlg,"SFW Batch Processor");
win.center();
if(version.substr(0,version.indexOf('.'))>9){
win.panel0.title.graphics.font = ScriptUI.newFont("Times","BOLDITALIC",26);
g = win.graphics;
b=win.panel0.title.graphics;
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.20, 1]);
g.backgroundColor = myBrush;
var myPen =b.newPen (g.PenType.SOLID_COLOR, [0.00, 0.00, 0.99, 1],lineWidth=1);
var myPen2 =b.newPen (g.PenType.SOLID_COLOR, [0.99, 0.00, 0.00, 1],lineWidth=1);
g.foregroundColor = myPen;
b.foregroundColor = myPen2;
}
win.panel0.panel1.Folder1.enabled=false;
win.panel0.panel1.Folder2.enabled=false;
var FileExtensions = "ALL,PSD,PDD,JPEG,JPG,JPE,GIF,BMP,RLE,DIB,TIF,CRW,NEF,RAF,ORF,CIN,DPX,EPS,PS,FLM,PSB,EXR,PCX,PDP," +
"PCD,RAW,PICT,PCT,PIC,PXR,PNG,TGA,VDA,ICB,VST,TIF,TIFF,WBM,DNG,SCT,PBM,CRW,CR2,DC2,DCR,NEF,MRW,X3F";
FileExtensions= FileExtensions.toUpperCase();
FileExtensions = FileExtensions.split(",");
FileExtensions= ReturnUniqueSortedList(FileExtensions);
for (i in FileExtensions) {
win.panel0.panel1.fileType.add('item',FileExtensions[i]);
}
win.panel0.panel1.fileType.selection=0;
for(var a = 0;a <101;a++){
win.panel0.panel1.qual.add('item',a);
}
win.panel0.panel1.qual.selection=80;
win.panel0.panel2.ResizeCheck.onClick = function() {
var realValue = win.panel0.panel2.ResizeCheck.value;
win.panel0.panel2.Width.enabled = realValue;
win.panel0.panel2.WW.enabled = realValue;
win.panel0.panel2.PX1.enabled = realValue;
win.panel0.panel2.Height.enabled = realValue;
win.panel0.panel2.HH.enabled = realValue;
win.panel0.panel2.PX2.enabled = realValue;
};
win.panel0.panel2.ResizeCheck.onClick();
win.panel0.panel2.Action.onClick = function() {
var RealValue = win.panel0.panel2.Action.value;
var resizeValue = win.panel0.panel2.ResizeCheck.value;
win.panel0.panel2.ActionSet.enabled = RealValue;
win.panel0.panel2.ActionName.enabled = RealValue;
};
win.panel0.panel1.Bridge.onClick =function(){
if(win.panel0.panel1.Bridge.value){
win.panel0.panel1.Folder1.text ='';
win.panel0.panel1.fileType.enabled=false;
win.panel0.panel1.Browse1.enabled=false;
}else{
win.panel0.panel1.fileType.enabled=true;
win.panel0.panel1.Browse1.enabled=true;
}
}
win.panel0.panel2.Action.onClick();
var actionSets = new Array();
actionSets = getActionSets();
for (var i=0,len=actionSets.length;i<len;i++) {
item = win.panel0.panel2.ActionSet.add ('item', "" + actionSets[i]);
};
win.panel0.panel2.ActionSet.selection=0;
var actions = new Array();
actions = getActions(actionSets[0]);
for (var i=0,len=actions.length;i<len;i++) {
item = win.panel0.panel2.ActionName.add ('item', "" + actions[i]);
};
win.panel0.panel2.ActionName.selection=0;
win.panel0.panel2.ActionSet.onChange = function() {
win.panel0.panel2.ActionName.removeAll();
actions = getActions(actionSets[parseInt(this.selection)]);
for (var i=0,len=actions.length;i<len;i++) {
item = win.panel0.panel2.ActionName.add ('item', "" + actions[i]);
}
win.panel0.panel2.ActionName.selection=0;
};
win.panel0.panel1.Browse1.onClick = function() {
if(!win.panel0.panel1.Bridge.value){
inputFolder = Folder.selectDialog("Please select the folder with Files to process",existFolder1);
if(inputFolder !=null){
existFolder1 = inputFolder;
win.panel0.panel1.Folder1.text = decodeURI(inputFolder.fsName);
}
}
}
win.panel0.panel1.Browse2.onClick = function() {
outputFolder = Folder.selectDialog("Please select the output folder",existFolder2);
if(outputFolder !=null){
existFolder2 = outputFolder;
win.panel0.panel1.Folder2.text = decodeURI(outputFolder.fsName);
}
}
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(inputFolder != '' && outputFolder != ''){
Ini.open("w");
Ini.writeln(inputFolder);
Ini.writeln(outputFolder);
Ini.close();
}
if(!win.panel0.panel1.Bridge.value){
if(win.panel0.panel1.Folder1.text == '') return 'No Source Folder selected';
if(win.panel0.panel1.Folder1.text == win.panel0.panel1.Folder2.text) return "Sorry input/output must be a different Folder";
}
if(win.panel0.panel1.Bridge.value){
Ini.open("w");
Ini.writeln(existFolder1);
Ini.writeln(outputFolder);
Ini.close();
}
if(win.panel0.panel1.Folder2.text == '') return 'No Output Folder selected';
if(win.panel0.panel2.ResizeCheck.value){
var WIDTH = parseInt(win.panel0.panel2.Width.text);
var HEIGHT= parseInt(win.panel0.panel2.Height.text);
if((isNaN(WIDTH)) || (WIDTH < 1)) return "Not a valid entry!\nResize Width MUST be greater than 1.";
if((isNaN(HEIGHT)) || (HEIGHT < 1)) return "Not a valid entry!\nResize Height MUST be greater than 1.";
}
return true;
}
function ProcessFolder(){
app.displayDialogs = DialogModes.NO;
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
if(!win.panel0.panel1.Bridge.value){
if(win.panel0.panel1.fileType.selection.text == 'ALL'){
var fileList = inputFolder.getFiles(/\.(jpg|jpe|jpeg|gif|eps|dng|bmp|tif|tiff|psd|crw|cr2|rle|dib|cin|dpx|ps|pcd|pict|vda|icb|vst|wbm|sct|pbm|flm|psb|exr|pcx|pdp|nef|dcr|dc2|erf|raf|orf|tga|mrw|mos|srf|pic|pct|pxr|pdd|pef|png|x3f|raw)$/i);
}else{
var str = "\\."+win.panel0.panel1.fileType.selection.text.toLowerCase()+"$";
var fileMask = new RegExp(str, "i");
var fileList = inputFolder.getFiles(fileMask);
}}
continues in next post for GFY's max characters allowed...
|