Copy link to clipboard
Copied
Dear all,
I can see that this question has been asked a few times, but the answers don't work for me.
All I need to do is to make a script (I am new to this).. which automates the transfer of the paths to the document with the same file name.
E.g.: File 1: Original tif or .psd file with file name fridaystudios64 which resides in a folder called tif. File 2: Jpg image which has been sent away for clipping and has come back. It also has the same filename fridaystudio64 but resides in a folder called Paths..
The file name is always different.. and there are over 10 for each batch.
The file size of these documents is exactly the same, but the colour space is different.. (the tif or .psd is Adobe RGB and the jpg is sRGB).
The file needs to automate by recognising the other file with the same name, opening up, and copying it over, and then just saving it.
I could do this manually, but it takes about 3 minutes a day, and sometimes longer, and thought if it's possible then it would be cool.
Can anyone please help with this, or already have a script they are generous enough to give me..
Kind regards,
Copy link to clipboard
Copied
As far as I know, you can't save a jpg with paths. They will be removed in the saving process. So I'm assuming that you want to save the jpgs as PSDs. What platform are you using: Mac or Win? What were the ways that didn't work for you?
Copy link to clipboard
Copied
As far as I know, you can't save a jpg with paths.
jpgs can contain Paths, at least now.
Edit: »Now« might be be an incorrect term, but I have no problems with Paths in jpgs.
Copy link to clipboard
Copied
Does this help?
// select folder, if folder »paths« exists beside that folder transfer paths from jpgs to psds, tifs from first folder;
// 2014, use it at your own risk;
#target photoshop
// dialog for folder-selection;
var theFolder1 = Folder.selectDialog ("select folder 1");
var theFolder2 = Folder(theFolder1.parent+"/Paths");
//var theFolder2 = Folder.selectDialog ("select folder 2");
if (theFolder1 && theFolder1) {
var theFiles1 = theFolder1.getFiles(getSomeFiles);
// work through folders;
for (var m = 0; m < theFiles1.length; m++) {
var theFile = theFiles1
; // if corresponding jpg exists;
var thePath = theFolder2+"/"+theFile.name.replace(/\.\D{3}$/i, ".jpg");
if (File(thePath).exists == true) {
// open jpg;
var theFile2 = app.open(File(thePath));
// if jpg has path/s;
if (theFile2.pathItems.length > 0) {
var thePaths = new Array;
var theNames = new Array;
// collect paths;
for (var n = 0; n < theFile2.pathItems.length; n++) {
var thisPath = theFile2.pathItems
; theNames.push (thisPath.name);
thePaths.push (collectPathInfoFromDesc2012(theFile2, thisPath));
};
theFile2.close(SaveOptions.DONOTSAVECHANGES)
// open other file;
var theFile = app.open(theFile);
// create paths;
for (var o = 0; o < thePaths.length; o++) {
var theName = theNames
; // if path of that name exists;
var theCheck = false
while (theCheck == false) {
try {
theFile.pathItems.getByName(theName);
theName = theName + "_"
}
catch (e) {theCheck = true};
};
createPath2012(thePaths
, theName) };
// close and save;
theFile.close(SaveOptions.SAVECHANGES);
}
else {theFile2.close(SaveOptions.DONOTSAVECHANGES)}
};
}
};
////// get psds and tifs from files //////
function getSomeFiles (theFile) {
if (theFile.name.match(/\.(tif|psd)$/i)) {
return true
};
};
////// get document’s //////
function getDocumentsID () {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var docDesc = executeActionGet(ref);
var docID = docDesc.getInteger(stringIDToTypeID("documentID"));
var docIndex = docDesc.getInteger(stringIDToTypeID("itemIndex"));
return [docID, docIndex]
};
////// collect path info from actiondescriptor, smooth added //////
function collectPathInfoFromDesc2012 (myDocument, thePath) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// based of functions from xbytor’s stdlib;
var ref = new ActionReference();
for (var l = 0; l < myDocument.pathItems.length; l++) {
var thisPath = myDocument.pathItems
; if (thisPath == thePath && thisPath.name == "Work Path") {
ref.putProperty(cTID("Path"), cTID("WrPt"));
};
if (thisPath == thePath && thisPath.name != "Work Path" && thisPath.kind != PathKind.VECTORMASK) {
ref.putIndex(cTID("Path"), l + 1);
};
if (thisPath == thePath && thisPath.kind == PathKind.VECTORMASK) {
var idPath = charIDToTypeID( "Path" );
var idPath = charIDToTypeID( "Path" );
var idvectorMask = stringIDToTypeID( "vectorMask" );
ref.putEnumerated( idPath, idPath, idvectorMask );
};
};
var desc = app.executeActionGet(ref);
var pname = desc.getString(cTID('PthN'));
// create new array;
var theArray = new Array;
var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));
// for subpathitems;
for (var m = 0; m < pathComponents.count; m++) {
var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));
var operation1 = pathComponents.getObjectValue(m).getEnumerationValue(sTID("shapeOperation"));
switch (operation1) {
case 1097098272:
var operation = 1097098272 //cTID('Add ');
break;
case 1398961266:
var operation = 1398961266 //cTID('Sbtr');
break;
case 1231975538:
var operation = 1231975538 //cTID('Intr');
break;
default:
// case 1102:
var operation = sTID('xor') //ShapeOperation.SHAPEXOR;
break;
};
// for subpathitem’s count;
for (var n = 0; n < listKey.count; n++) {
theArray.push(new Array);
var points = listKey.getObjectValue(n).getList(sTID('points'));
try {var closed = listKey.getObjectValue(n).getBoolean(sTID("closedSubpath"))}
catch (e) {var closed = false};
// for subpathitem’s segment’s number of points;
for (var o = 0; o < points.count; o++) {
var anchorObj = points.getObjectValue(o).getObjectValue(sTID("anchor"));
var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];
var thisPoint = [anchor];
try {
var left = points.getObjectValue(o).getObjectValue(cTID("Fwd "));
var leftDirection = [left.getUnitDoubleValue(sTID('horizontal')), left.getUnitDoubleValue(sTID('vertical'))];
thisPoint.push(leftDirection)
}
catch (e) {
thisPoint.push(anchor)
};
try {
var right = points.getObjectValue(o).getObjectValue(cTID("Bwd "));
var rightDirection = [right.getUnitDoubleValue(sTID('horizontal')), right.getUnitDoubleValue(sTID('vertical'))];
thisPoint.push(rightDirection)
}
catch (e) {
thisPoint.push(anchor)
};
try {
var smoothOr = points.getObjectValue(o).getBoolean(cTID("Smoo"));
thisPoint.push(smoothOr)
}
catch (e) {thisPoint.push(false)};
theArray[theArray.length - 1].push(thisPoint);
};
theArray[theArray.length - 1].push(closed);
theArray[theArray.length - 1].push(operation);
};
};
// by xbytor, thanks to him;
function cTID (s) { return cTID
|| cTID= app.charIDToTypeID(s); };function sTID (s) { return sTID
|| sTID= app.stringIDToTypeID(s); };// reset;
app.preferences.rulerUnits = originalRulerUnits;
return theArray;
};
////// create a path from collectPathInfoFromDesc2012-array //////
function createPath2012(theArray, thePathsName) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// thanks to xbytor;
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Path'), cTID('WrPt'));
desc1.putReference(sTID('null'), ref1);
var list1 = new ActionList();
for (var m = 0; m < theArray.length; m++) {
var thisSubPath = theArray
; var desc2 = new ActionDescriptor();
desc2.putEnumerated(sTID('shapeOperation'), sTID('shapeOperation'), thisSubPath[thisSubPath.length - 1]);
var list2 = new ActionList();
var desc3 = new ActionDescriptor();
desc3.putBoolean(cTID('Clsp'), thisSubPath[thisSubPath.length - 2]);
var list3 = new ActionList();
for (var n = 0; n < thisSubPath.length - 2; n++) {
var thisPoint = thisSubPath
; var desc4 = new ActionDescriptor();
var desc5 = new ActionDescriptor();
desc5.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[0][0]);
desc5.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[0][1]);
desc4.putObject(cTID('Anch'), cTID('Pnt '), desc5);
var desc6 = new ActionDescriptor();
desc6.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[1][0]);
desc6.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[1][1]);
desc4.putObject(cTID('Fwd '), cTID('Pnt '), desc6);
var desc7 = new ActionDescriptor();
desc7.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[2][0]);
desc7.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[2][1]);
desc4.putObject(cTID('Bwd '), cTID('Pnt '), desc7);
desc4.putBoolean(cTID('Smoo'), thisPoint[3]);
list3.putObject(cTID('Pthp'), desc4);
};
desc3.putList(cTID('Pts '), list3);
list2.putObject(cTID('Sbpl'), desc3);
desc2.putList(cTID('SbpL'), list2);
list1.putObject(cTID('PaCm'), desc2);
};
desc1.putList(cTID('T '), list1);
executeAction(cTID('setd'), desc1, DialogModes.NO);
if (hasVectorMask() == false) {
var myPathItem = app.activeDocument.pathItems[app.activeDocument.pathItems.length - 1];
}
else {
var myPathItem = app.activeDocument.pathItems[app.activeDocument.pathItems.length - 2];
};
myPathItem.name = thePathsName;
app.preferences.rulerUnits = originalRulerUnits;
return myPathItem
};
// from »Flatten All Masks.jsx« by jeffrey tranberry;
///////////////////////////////////////////////////////////////////////////////
// Function: hasVectorMask
// Usage: see if there is a vector layer mask
// Input: <none> Must have an open document
// Return: true if there is a vector mask
///////////////////////////////////////////////////////////////////////////////
function hasVectorMask() {
var hasVectorMask = false;
try {
var ref = new ActionReference();
var keyVectorMaskEnabled = app.stringIDToTypeID( 'vectorMask' );
var keyKind = app.charIDToTypeID( 'Knd ' );
ref.putEnumerated( app.charIDToTypeID( 'Path' ), app.charIDToTypeID( 'Ordn' ), keyVectorMaskEnabled );
var desc = executeActionGet( ref );
if ( desc.hasKey( keyKind ) ) {
var kindValue = desc.getEnumerationValue( keyKind );
if (kindValue == keyVectorMaskEnabled) {
hasVectorMask = true;
}
}
}catch(e) {
hasVectorMask = false;
}
return hasVectorMask;
};
Copy link to clipboard
Copied
Very comprehensive script, c.pfaffenbichler! I was going to try putting one together by just coping and pasting the paths in a loop like:
sourceDoc = app.documents[0]
targetDoc = app.documents[1]//or from array of files from a folder
activeDocument = sourceDoc
for(vari=0;i<sourceDoc.pathItems.length;i++)[
sourceDoc.pathItems.select()
var idcopy = charIDToTypeID( "copy" );
executeAction( idcopy, undefined, DialogModes.NO );
activeDocument = targetDoc
var idpast = charIDToTypeID( "past" );
executeAction( idpast, undefined, DialogModes.NO );
activeDocument = sourceDoc
}
Of course have all that stuff to get the files from a folder and check the file name. Just wondering what would be faster in excuting: redrawing the paths or copying and pasting, but jumping from document to document to do so.
Copy link to clipboard
Copied
I hadn’t even thought of copying the Paths.
I suspect it may be a bit slower but it also may be more secure – but I haven’t actually run the tests to measure the time.
Edit: But I suppose the time may be not much of a factor, so long as the OP does not have to perform the task manually.
Copy link to clipboard
Copied
I suppose it would also depend upon how complex the paths are. Yes, either method is better than doing it manually!!!
Copy link to clipboard
Copied
is there a similar script for alpha channels?
Thank you and best regards
Copy link to clipboard
Copied
I am not aware of a script to move alpha channels from a source document to a target document. There is a native feature for this in the GUI of the software. How many channels do you wish to move from Doc A to Doc B, and on how many files do you need this to work?
Copy link to clipboard
Copied
You could most likely use scriptListener to record Apply image to transfer alpha chanels.
Copy link to clipboard
Copied
Agreed Chuck, either apply image or the duplicate channels command can do the job, it is just going to be a case of working out the best way to script this as one is going to have to preset which is the source and which is the destination doc, cycle through the channels one by one for an automated result. A semi-auto process should be doable in action or script, however a fully automated approach is gong to take more work.
Copy link to clipboard
Copied
Thank you for your help.
the script with transfering paths works really fine for my needs.
I try to describe my problem.
Sometimes I have to send my images (most of the time) to external service providers like clippingpath.
To save time I upload tiffs and they mask the portraits so I can change the background.
i would really like to have the alpha channels in my original psd document to keep a clean file structure.
Sometimes there are 50 portraits, sometimes there are 100. the Images which contain the masks have the same name as the psd working files. most of the time they contain one extra channel, sometimes more.
to do all this work manually or semi-Auto process also takes to much time. I would like to run a script like the one with transferring the paths, so I can do other work while the channels are transferred to the psd files.
thank you again in advice and best regards
Copy link to clipboard
Copied
Sounds like it is time to create a new topic thread specifically on transferring channels in the scripting forum and reference this topic.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Wow.. did you write this whole script.. I am amazed.. thank you so much!
I will test it but currently having computer issues. Can you please clarify.. do I need to copy and paste the entire thing, from "// select folder" to "return hasVectorMask ; };" into a .jsx file (from script listener), and save then load into photoshop?
Once again thank you!
Copy link to clipboard
Copied
Paste the text into a new file in ExtendScript Toolkit (part of Photoshop’s installation, Applications/Utilities/Adobe Utilities/ExtendScript Toolkit … and save it as a jsx-file into Photoshop’s Presets/Scripts-folder.
After restarting Photoshop the Script should be available under File > Scripts and can be assigned a Keyboard Shortcut directly, recorded into an Action, be used in a Configurator-Panel or started from ExtendScript Toolkit directly.
Copy link to clipboard
Copied
Great, thanks.. will try and test this in the next few days (probably better not to test it on studio computers in case it messes something up). I know it's a silly question, but do I also include this part of the script:?
"// select folder, if folder »paths« exists beside that folder transfer paths from jpgs to psds, tifs from first folder;
// 2014, use it at your own risk;"
Or does the script start from:
"#target photoshop
// dialog for folder-selection;
var theFolder1 = Folder.selectDialog ("select folder 1");"
Just to confirm.. I my pathed images should be in a folder called "Paths", and the files that the paths are being copied to should be in a folder called "Tif"?
Sorry for all the questions.. but thank you, very kind of you to help and share your knowledge! ..do you know if there are any basic lessons on Photoshop scripting which could teach me for beginners then hopefully allow me to progress?
Thank you,
Copy link to clipboard
Copied
I know it's a silly question, but do I also include this part of the script:?
What’s keeping you from it?
Text between »//« and a line-break and text between »/*« and »*/« do not perform but usually serve as comments.
I my pathed images should be in a folder called "Paths", and the files that the paths are being copied to should be in a folder called "Tif"?
The name of the folder with the psds is irrelevant, the folder with the pathed files must be named »Paths«, but you can change that in the Script yourself in this line
var theFolder2 = Folder(theFolder1.parent+"/Paths");
do you know if there are any basic lessons on Photoshop scripting which could teach me for beginners then hopefully allow me to progress?
»Adobe Intro To Scripting.pdf« might serve as a non-Photoshop-specific introduction, but it may unfortunately not be very engaging …
Copy link to clipboard
Copied
Yeah it is progressing.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now