Hello everyones,
I have that script below. I want to open a dialog box before the script crop picture and ask me where are the photos to be cropped.
How I do that please?
tks
Seby
Code: Select all// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc11 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref6 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref6.putProperty( idChnl, idfsel );
desc11.putReference( idnull, ref6 );
var idT = charIDToTypeID( "T " );
var idOrdn = charIDToTypeID( "Ordn" );
var idAl = charIDToTypeID( "Al " );
desc11.putEnumerated( idT, idOrdn, idAl );
executeAction( idsetd, desc11, DialogModes.NO );
// =======================================================
var idcopy = charIDToTypeID( "copy" );
executeAction( idcopy, undefined, DialogModes.NO );
// =======================================================
var oldRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.INCHES;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
if (myDocument.height < myDocument.width) {
myDocument.resizeImage(7, 5, 300, ResampleMethod.BICUBIC);
}else{
myDocument.resizeImage(5, 7, 300, ResampleMethod.BICUBIC);
} ;
};
// =======================================================
var idRset = charIDToTypeID( "Rset" );
var desc14 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref8 = new ActionReference();
var idClr = charIDToTypeID( "Clr " );
var idClrs = charIDToTypeID( "Clrs" );
ref8.putProperty( idClr, idClrs );
desc14.putReference( idnull, ref8 );
executeAction( idRset, desc14, DialogModes.NO );
// =======================================================
var idFl = charIDToTypeID( "Fl " );
var desc15 = new ActionDescriptor();
var idUsng = charIDToTypeID( "Usng" );
var idFlCn = charIDToTypeID( "FlCn" );
var idBckC = charIDToTypeID( "BckC" );
desc15.putEnumerated( idUsng, idFlCn, idBckC );
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc15.putUnitDouble( idOpct, idPrc, 100.000000 );
var idMd = charIDToTypeID( "Md " );
var idBlnM = charIDToTypeID( "BlnM" );
var idNrml = charIDToTypeID( "Nrml" );
desc15.putEnumerated( idMd, idBlnM, idNrml );
executeAction( idFl, desc15, DialogModes.NO );
// =======================================================
var idpast = charIDToTypeID( "past" );
var desc16 = new ActionDescriptor();
var idAntA = charIDToTypeID( "AntA" );
var idAnnt = charIDToTypeID( "Annt" );
var idAnno = charIDToTypeID( "Anno" );
desc16.putEnumerated( idAntA, idAnnt, idAnno );
executeAction( idpast, desc16, DialogModes.NO );
// =======================================================
var idslct = charIDToTypeID( "slct" );
var desc17 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref9 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idBack = charIDToTypeID( "Back" );
ref9.putEnumerated( idLyr, idOrdn, idBack );
desc17.putReference( idnull, ref9 );
var idselectionModifier = stringIDToTypeID( "selectionModifier" );
var idselectionModifierType = stringIDToTypeID( "selectionModifierType" );
var idaddToSelectionContinuous = stringIDToTypeID( "addToSelectionContinuous" );
desc17.putEnumerated( idselectionModifier, idselectionModifierType, idaddToSelectionContinuous );
var idMkVs = charIDToTypeID( "MkVs" );
desc17.putBoolean( idMkVs, false );
executeAction( idslct, desc17, DialogModes.NO );
// =======================================================
var idAlgn = charIDToTypeID( "Algn" );
var desc18 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref10 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref10.putEnumerated( idLyr, idOrdn, idTrgt );
desc18.putReference( idnull, ref10 );
var idUsng = charIDToTypeID( "Usng" );
var idADSt = charIDToTypeID( "ADSt" );
var idAdCV = charIDToTypeID( "AdCV" );
desc18.putEnumerated( idUsng, idADSt, idAdCV );
executeAction( idAlgn, desc18, DialogModes.NO );
// =======================================================
var idAlgn = charIDToTypeID( "Algn" );
var desc19 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref11 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref11.putEnumerated( idLyr, idOrdn, idTrgt );
desc19.putReference( idnull, ref11 );
var idUsng = charIDToTypeID( "Usng" );
var idADSt = charIDToTypeID( "ADSt" );
var idAdCH = charIDToTypeID( "AdCH" );
desc19.putEnumerated( idUsng, idADSt, idAdCH );
executeAction( idAlgn, desc19, DialogModes.NO );
// =======================================================
var idslct = charIDToTypeID( "slct" );
var desc20 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref12 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idFrnt = charIDToTypeID( "Frnt" );
ref12.putEnumerated( idLyr, idOrdn, idFrnt );
desc20.putReference( idnull, ref12 );
var idMkVs = charIDToTypeID( "MkVs" );
desc20.putBoolean( idMkVs, false );
executeAction( idslct, desc20, DialogModes.NO );
// =======================================================
function ScaleToFit(pLyr, pTargetLayer) {
try {
var cw;
var ch;
var targetx;
var targety;
if (pTargetLayer.typename == "ArtLayer") {
cw =pTargetLayer.bounds[2].as('px') - pTargetLayer.bounds[0].as('px');
ch = pTargetLayer.bounds[3].as('px') - pTargetLayer.bounds[1].as('px');
targetx = pTargetLayer.bounds[0].as('px') + cw/2;
targety = pTargetLayer.bounds[1].as('px') + ch/2;
} else if (pTargetLayer.typename == "Document") {
cw =pTargetLayer.width.as('px');
ch = pTargetLayer.height.as('px');
targetx = cw/2;
targety = ch/2;
} else {
//invalid type
return;
}
var lw = pLyr.bounds[2].as('px') - pLyr.bounds[0].as('px');
var lh = pLyr.bounds[3].as('px') - pLyr.bounds[1].as('px');
var rWidth = cw/lw;
var rHeight = ch/lh;
if (rWidth != 1 && rHeight != 1) {
if (rWidth > rHeight) {
//resize up by rwidth as a percent
pLyr.resize(rWidth * 105, rWidth * 105);
} else {
//resize up by rheight as a percent
var t = rHeight * 100;
pLyr.resize(rHeight * 105, rHeight * 105);
}
}
lw = pLyr.bounds[2].as('px') - pLyr.bounds[0].as('px');
lh = pLyr.bounds[3].as('px') - pLyr.bounds[1].as('px');
var currx = pLyr.bounds[0].as('px') + lw/2;
var curry = pLyr.bounds[1].as('px') + lh/2;
pLyr.translate(targetx - currx, targety - curry);
} catch (e) {
//ignore
}
}
ScaleToFit(app.activeDocument.activeLayer, app.activeDocument);
// =======================================================
var idslct = charIDToTypeID( "slct" );
var desc10 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref4 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idBack = charIDToTypeID( "Back" );
ref4.putEnumerated( idLyr, idOrdn, idBack );
desc10.putReference( idnull, ref4 );
var idselectionModifier = stringIDToTypeID( "selectionModifier" );
var idselectionModifierType = stringIDToTypeID( "selectionModifierType" );
var idaddToSelectionContinuous = stringIDToTypeID( "addToSelectionContinuous" );
desc10.putEnumerated( idselectionModifier, idselectionModifierType, idaddToSelectionContinuous );
var idMkVs = charIDToTypeID( "MkVs" );
desc10.putBoolean( idMkVs, false );
executeAction( idslct, desc10, DialogModes.NO );
// =======================================================
var idslct = charIDToTypeID( "slct" );
var desc11 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref5 = new ActionReference();
var idmoveTool = stringIDToTypeID( "moveTool" );
ref5.putClass( idmoveTool );
desc11.putReference( idnull, ref5 );
var iddontRecord = stringIDToTypeID( "dontRecord" );
desc11.putBoolean( iddontRecord, true );
var idforceNotify = stringIDToTypeID( "forceNotify" );
desc11.putBoolean( idforceNotify, true );
executeAction( idslct, desc11, DialogModes.NO );
// =======================================================
var idAlgn = charIDToTypeID( "Algn" );
var desc12 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref6 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref6.putEnumerated( idLyr, idOrdn, idTrgt );
desc12.putReference( idnull, ref6 );
var idUsng = charIDToTypeID( "Usng" );
var idADSt = charIDToTypeID( "ADSt" );
var idAdCV = charIDToTypeID( "AdCV" );
desc12.putEnumerated( idUsng, idADSt, idAdCV );
executeAction( idAlgn, desc12, DialogModes.NO );
// =======================================================
var idAlgn = charIDToTypeID( "Algn" );
var desc13 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref7 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref7.putEnumerated( idLyr, idOrdn, idTrgt );
desc13.putReference( idnull, ref7 );
var idUsng = charIDToTypeID( "Usng" );
var idADSt = charIDToTypeID( "ADSt" );
var idAdCH = charIDToTypeID( "AdCH" );
desc13.putEnumerated( idUsng, idADSt, idAdCH );
executeAction( idAlgn, desc13, DialogModes.NO );
// =======================================================
var idslct = charIDToTypeID( "slct" );
var desc14 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref8 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idFrnt = charIDToTypeID( "Frnt" );
ref8.putEnumerated( idLyr, idOrdn, idFrnt );
desc14.putReference( idnull, ref8 );
var idMkVs = charIDToTypeID( "MkVs" );
desc14.putBoolean( idMkVs, false );
executeAction( idslct, desc14, DialogModes.NO );
// Fit OnScreen
var id29 = charIDToTypeID( "slct" );
var desc7 = new ActionDescriptor();
var id30 = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var id31 = charIDToTypeID( "Mn " );
var id32 = charIDToTypeID( "MnIt" );
var id33 = charIDToTypeID( "FtOn" );
ref2.putEnumerated( id31, id32, id33 );
desc7.putReference( id30, ref2 );
executeAction( id29, desc7, DialogModes.NO );
// =======================================================
var idTrnf = charIDToTypeID( "Trnf" );
var desc60 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref35 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref35.putEnumerated( idLyr, idOrdn, idTrgt );
desc60.putReference( idnull, ref35 );
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc60.putEnumerated( idFTcs, idQCSt, idQcsa );
var idOfst = charIDToTypeID( "Ofst" );
var desc61 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idRlt = charIDToTypeID( "#Rlt" );
desc61.putUnitDouble( idHrzn, idRlt, -0.000000 );
var idVrtc = charIDToTypeID( "Vrtc" );
var idRlt = charIDToTypeID( "#Rlt" );
desc61.putUnitDouble( idVrtc, idRlt, 0.000000 );
var idOfst = charIDToTypeID( "Ofst" );
desc60.putObject( idOfst, idOfst, desc61 );
var idWdth = charIDToTypeID( "Wdth" );
var idPrc = charIDToTypeID( "#Prc" );
desc60.putUnitDouble( idWdth, idPrc, 99.990000 );
var idHght = charIDToTypeID( "Hght" );
var idPrc = charIDToTypeID( "#Prc" );
desc60.putUnitDouble( idHght, idPrc, 99.990000 );
var idLnkd = charIDToTypeID( "Lnkd" );
desc60.putBoolean( idLnkd, true );
executeAction( idTrnf, desc60, DialogModes.ALL );
//1. Flatten Image =======================================
var id12 = charIDToTypeID( "FltI" );
executeAction( id12, undefined, DialogModes.NO );
//2. Convert to 8-bit mode ===============================
var id13 = charIDToTypeID( "CnvM" );
var desc4 = new ActionDescriptor();
var id14 = charIDToTypeID( "Dpth" );
desc4.putInteger( id14, 8 );
executeAction( id13, desc4, DialogModes.NO );
//3. Script to perform SAVEAS function//////////////////////////////////////////
// Usage: SaveAs function on existing open and active document in CS5
// Input: full name (path + filename) for the jpg
///////////////////////////////////////////////////////////////////////////////
// your active document
var doc = app.activeDocument;
// create crop folder //
var myfolder=new Folder(doc.path+"/"+'crop');
if (!(myfolder.created)) myfolder.create();
// save as jpeg with suffix. eg. "-processedHiRes.jpg"
// save as jpeg with suffix. eg. "-BlurbHiRes.jpg"
// save as jpeg with suffix. eg. "-processedScrRes.jpg"
var jpgQuality = 12;
var saveFile = doc.path + "/crop/" + doc.name.replace(/\.[^\.]+$/, '') + ".jpg";
SaveJPEG( new File(saveFile), jpgQuality );
function SaveJPEG(saveFile, jpegQuality){
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(saveFile, jpgSaveOptions);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
Open dialog box to process crop photos script
-
larsen67
Open dialog box to process crop photos script
Something like this will give you the dialog…
Code: Select allvar inFolder = Folder.selectDialog( 'Where are your files?' );
var fileList = inFolder.getFiles( /\.(jpg||psd||tif)$/i );
The in-built getFiles function can take regular expression as argument…
fileList should be an array you can loop…
Code: Select allvar inFolder = Folder.selectDialog( 'Where are your files?' );
var fileList = inFolder.getFiles( /\.(jpg||psd||tif)$/i );
The in-built getFiles function can take regular expression as argument…
fileList should be an array you can loop…
-
seby20
Open dialog box to process crop photos script
Hi tks I've tried this. But on MAC CS6 I have that error
Error: Cannot open the file because the open options are incorrect
Any idea why?
tks
Seby
Code: Select allinputFolder = Folder.selectDialog("Select To Open Image Folder")
OpenFolder(inputFolder);
function OpenFolder()
{
filesOpened = 0;
fileList = inputFolder.getFiles(); //getFiles(/.jpg/i) for only jpg .jpg
for ( i = 0; i < fileList.length; i++ )
{
open( fileList );
traiterImage();
}
return filesOpened;
}
function traiterImage()
{
... the rest of my script
Error: Cannot open the file because the open options are incorrect
Any idea why?
tks
Seby
Code: Select allinputFolder = Folder.selectDialog("Select To Open Image Folder")
OpenFolder(inputFolder);
function OpenFolder()
{
filesOpened = 0;
fileList = inputFolder.getFiles(); //getFiles(/.jpg/i) for only jpg .jpg
for ( i = 0; i < fileList.length; i++ )
{
open( fileList );
traiterImage();
}
return filesOpened;
}
function traiterImage()
{
... the rest of my script
-
seby20
Open dialog box to process crop photos script
larsen67 wrote:Something like this will give you the dialog…
Code: Select allvar inFolder = Folder.selectDialog( 'Where are your files?' );
var fileList = inFolder.getFiles( /\.(jpg||psd||tif)$/i );
The in-built getFiles function can take regular expression as argument…
fileList should be an array you can loop…
Hi, see up there, I've answered with the problem I've encounter.
tks
Seby
Code: Select allvar inFolder = Folder.selectDialog( 'Where are your files?' );
var fileList = inFolder.getFiles( /\.(jpg||psd||tif)$/i );
The in-built getFiles function can take regular expression as argument…
fileList should be an array you can loop…
Hi, see up there, I've answered with the problem I've encounter.
tks
Seby
-
seby20
Open dialog box to process crop photos script
Is there anyone with the same problem with this script on a MAC?
tks
Seby
tks
Seby
-
Mike Hale
Open dialog box to process crop photos script
I don't have a Mac to test with but in your code you have the line
fileList = inputFolder.getFiles();
That will get all the file in the inputFolder including non-image files, system files, and subfolders. If you don't filter the files using the getFiles() argument, you should at least make sure it's a valid image file before you try to open it.
And even if it is a valid image file, user permissions can sometimes cause that error depending in the user account settings and where inputFolder is located.
fileList = inputFolder.getFiles();
That will get all the file in the inputFolder including non-image files, system files, and subfolders. If you don't filter the files using the getFiles() argument, you should at least make sure it's a valid image file before you try to open it.
And even if it is a valid image file, user permissions can sometimes cause that error depending in the user account settings and where inputFolder is located.