View Single Post
Old 05-21-2009, 01:55 PM  
harvey
Confirmed User
 
harvey's Avatar
 
Industry Role:
Join Date: Jul 2001
Location: 127.0.0.1
Posts: 9,266
Code:
if(win.panel0.panel1.Bridge.value) var fileList= GetFilesFromBridge();
	for(var a =0;a<fileList.length;a++){
		 file = fileList[a];
		if(file instanceof File) {
			open(file);
			var FileName = file.name.split('.');
				var Filename = new File(decodeURI(outputFolder) + "/" + FileName[0] + ".jpg");
				var testFile = new File(decodeURI(outputFolder) + "/" + FileName[0] + ".jpg");
				var doc = activeDocument;
				if(win.panel0.panel2.ResizeCheck.value) FitImage( parseInt(win.panel0.panel2.Width.text), parseInt(win.panel0.panel2.Height.text) );
				if(win.panel0.panel2.Action.value) doAction(win.panel0.panel2.ActionName.selection.text, win.panel0.panel2.ActionSet.selection.text);	
				if(Filename.exists) testFile.rename(testFile.name.slice(0,-4) + time() + ".jpg");
				SaveForWeb(Filename,parseInt(win.panel0.panel1.qual.selection));
				app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 
		}
	} 
		app.preferences.rulerUnits = strtRulerUnits;  
		app.preferences.typeUnits = strtTypeUnits;	
}
}
if(version.substr(0,version.indexOf('.'))>8 && version.substr(0,version.indexOf('.'))<11){
var Ini = new File(app.preferencesFolder +"/SFW.ini");
if(!Ini.exists){
Ini.open("w");
Ini.writeln("");
Ini.writeln("");
Ini.close();
var existFolder1 = '';
var existFolder2 = '';
}else{
Ini.open("r");
var existFolder1 = Ini.readln();
var existFolder2 = Ini.readln();
Ini.close();	
	}
var inputFolder = '';
var outputFolder = '';
main();
}else{
	alert("Sorry this is for PhotoShop CS2 and CS3 Only");
}
function getActionSets() { 
cTID = function(s) { return app.charIDToTypeID(s); }; 
  var i = 1; 
  var sets = [];  
  while (true) { 
    var ref = new ActionReference(); 
    ref.putIndex(cTID("ASet"), i); 
    var desc; 
    var lvl = $.level; 
    $.level = 0; 
    try { 
      desc = executeActionGet(ref); 
    } catch (e) { 
      break;
    } finally { 
      $.level = lvl; 
    } 
    if (desc.hasKey(cTID("Nm  "))) { 
      var set = {}; 
      set.index = i; 
      set.name = desc.getString(cTID("Nm  ")); 
      set.toString = function() { return this.name; }; 
      set.count = desc.getInteger(cTID("NmbC")); 
      set.actions = []; 
      for (var j = 1; j <= set.count; j++) { 
        var ref = new ActionReference(); 
        ref.putIndex(cTID('Actn'), j); 
        ref.putIndex(cTID('ASet'), set.index); 
        var adesc = executeActionGet(ref); 
        var actName = adesc.getString(cTID('Nm  ')); 
        set.actions.push(actName); 
      } 
      sets.push(set); 
    } 
    i++; 
  } 
  return sets; 
}; 

function getActions(aset) {
cTID = function(s) { return app.charIDToTypeID(s); }; 
  var i = 1;
  var names = [];
  if (!aset) {
    throw "Action set must be specified";
  }  
  while (true) {
    var ref = new ActionReference();
    ref.putIndex(cTID("ASet"), i);
    var desc;
    try {
      desc = executeActionGet(ref);
    } catch (e) {
      break; 
    }
    if (desc.hasKey(cTID("Nm  "))) {
      var name = desc.getString(cTID("Nm  "));
      if (name == aset) {
        var count = desc.getInteger(cTID("NmbC"));
        var names = [];
        for (var j = 1; j <= count; j++) {
          var ref = new ActionReference();
          ref.putIndex(cTID('Actn'), j);
          ref.putIndex(cTID('ASet'), i);
          var adesc = executeActionGet(ref);
          var actName = adesc.getString(cTID('Nm  '));
          names.push(actName);
        }
        break;
      }
    }
    i++;
  }
  return names;
};

function FitImage( inWidth, inHeight ) {
	var desc = new ActionDescriptor();
	var unitPixels = charIDToTypeID( '#Pxl' );
	desc.putUnitDouble( charIDToTypeID( 'Wdth' ), unitPixels, inWidth );
	desc.putUnitDouble( charIDToTypeID( 'Hght' ), unitPixels, inHeight );
	var runtimeEventID = stringIDToTypeID( "3caa3434-cb67-11d1-bc43-0060b0a13dc4" );	
	executeAction( runtimeEventID, desc, DialogModes.NO );
}
function ReturnUniqueSortedList(ArrayName){
var unduped = new Object;
for (var i = 0; i < ArrayName.length; i++) {   
unduped[ArrayName[i]] = ArrayName[i];
}
var uniques = new Array;for (var k in unduped) {
   uniques.push(unduped[k]);
   }
uniques.sort();
return uniques;
}
function SaveForWeb(saveFile,jpegQuality) {
var sfwOptions = new ExportOptionsSaveForWeb(); 
   sfwOptions.format = SaveDocumentType.JPEG; 
   sfwOptions.includeProfile = false; 
   sfwOptions.interlaced = 0; 
   sfwOptions.optimized = true; 
   sfwOptions.quality = jpegQuality; 
activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);
}
function time(){
var date = new Date();
	var d  = date.getDate();
	var day = (d < 10) ? '0' + d : d;
	var m = date.getMonth() + 1;
	var month = (m < 10) ? '0' + m : m;
	var yy = date.getYear();
	var year = (yy < 1000) ? yy + 1900 : yy;
	var digital = new Date();
	var hours = digital.getHours();
	var minutes = digital.getMinutes();
	var seconds = digital.getSeconds();
	var amOrPm = "AM";
	if (hours > 11) amOrPm = "PM";
	if (hours > 12) hours = hours - 12;
	if (hours == 0) hours = 12;
	if (minutes <= 9) minutes = "0" + minutes;
	if (seconds <= 9) seconds = "0" + seconds;
	todaysDate = "-" + hours + "_" + minutes + "_" + seconds + amOrPm;
	return todaysDate.toString();
};
function GetFilesFromBridge() {
	var fileList;
	if ( BridgeTalk.isRunning( "bridge" ) ) {
		var bt = new BridgeTalk();
		bt.target = "bridge";
		bt.body = "var theFiles = photoshop.getBridgeFileListForAutomateCommand();theFiles.toSource();";
		bt.onResult = function( inBT ) { fileList = eval( inBT.body ); }
		bt.onError = function( inBT ) { fileList = new Array(); }
		bt.send();
		bt.pump();
		$.sleep( 100 );
		var timeOutAt = ( new Date() ).getTime() + 5000;
		var currentTime = ( new Date() ).getTime();
		while ( ( currentTime < timeOutAt ) && ( undefined == fileList ) ) {
			bt.pump();
			$.sleep( 100 );
			currentTime = ( new Date() ).getTime();
		}
	}
	if ( undefined == fileList ) {
		fileList = new Array();
	}
	return fileList; 
}
now join both code parts, save it with any name you want and extension .jsx and place it in your scripts folder, usually C:/Program Files/Adobe/Adobe Photoshop CS2/Presets/Scripts/ (or CS3 if you use CS3, I'm poor and legit )
__________________
This post is endorsed by CIA, KGB, MI6, the Mafia, Illuminati, Kim Jong Il, Worldwide Ninjas Association, Klingon Empire and lolcats. Don't mess around with it, just accept it and embrace the truth
harvey is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote