Copy link to clipboard
Copied
Hey guys, I'm fairly inexperienced with scripts and have been lucky with some of the ones I've altered to fit my needs.
I'm trying to create a script that would save a Large Document Format (PSB) for in the activeDocument.Path with a subfolder called Edits. So I found something like this:
var subFolder = new Folder(activeDocument.path + '/Edits/') if (!subFolder.exists){subFolder.create()};
Do you guys have any ideas how to do that? If you need more information please let me know. I know it might be vague.
if (activeDocument.path.fsName.search(/[\/\\]Edits$/i) >= 0)
{
var file = activeDocument.fullName;
}
else
{
var folder = new Folder(activeDocument.path.fsName + "/Edits"); if (!folder.exists) folder.create();
var file = new File(folder.fsName + "/" + activeDocument.name);
}
var d = new ActionDescriptor();
var d1 = new ActionDescriptor();
d1.putBoolean(stringIDToTypeID("maximizeCompatibility"), false);
d.putObject(stringIDToTypeID("as"), stringIDToTypeID("largeD
...
Copy link to clipboard
Copied
I'm working with this code and it works but I'd like it to create a sub-folder in the path that it saves:
var d = app.activeDocument;
var dPath = d.path;
var dname = d.name.replace(/\.[^\.]+$/, '');
var idsave = charIDToTypeID( "save" );
var desc17 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc18 = new ActionDescriptor();
var idPhteight = charIDToTypeID( "Pht8" );
desc17.putObject( idAs, idPhteight, desc18 );
var idIn = charIDToTypeID( "In " );
desc17.putPath( idIn, new File( dPath + '/' + dname + '.psb' ) );
var idDocI = charIDToTypeID( "DocI" );
desc17.putInteger( idDocI, 195 );
var idCpy = charIDToTypeID( "Cpy " );
desc17.putBoolean( idCpy, true );
var idLwCs = charIDToTypeID( "LwCs" );
desc17.putBoolean( idLwCs, true );
var idsaveStage = stringIDToTypeID( "saveStage" );
var idsaveStageType = stringIDToTypeID( "saveStageType" );
var idsaveSucceeded = stringIDToTypeID( "saveSucceeded" );
desc17.putEnumerated( idsaveStage, idsaveStageType, idsaveSucceeded );
executeAction( idsave, desc17, DialogModes.NO );
Copy link to clipboard
Copied
Try something like this:
var d = app.activeDocument;
var dPath = d.path;
var dname = d.name.replace(/\.[^\.]+$/, '');
var subFolder = new Folder(dPath + '/Edits/');
if (!subFolder.exists) { subFolder.create() };
function c2t(s) {
return app.charIDToTypeID(s);
}
function s2t(s) {
return app.stringIDToTypeID(s);
}
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
descriptor.putObject(s2t("as"), s2t("largeDocumentFormat"), descriptor2);
descriptor.putPath(c2t("In "), new File(subFolder + '/' + dname + '.psb'));
descriptor.putBoolean(s2t("copy"), true);
descriptor.putBoolean(s2t("lowerCase"), true);
executeAction(s2t("save"), descriptor, DialogModes.NO);
Copy link to clipboard
Copied
This works perfectly, how I would I stop it from making an endless chain of sub-folders now and just continue to save in the folder initially made?
Copy link to clipboard
Copied
check it
try {
var folder = new Folder(activeDocument.path.fsName + "/Edits"); if (!folder.exists) folder.create();
var file = new File(folder.fsName + "/" + activeDocument.name);
var d = new ActionDescriptor();
var d1 = new ActionDescriptor();
d1.putBoolean(stringIDToTypeID("maximizeCompatibility"), false);
d.putObject(stringIDToTypeID("as"), stringIDToTypeID("largeDocumentFormat"), d1);
d.putPath(stringIDToTypeID("in"), file);
d.putBoolean(stringIDToTypeID("copy"), true); // true == save copy of current document
d.putBoolean(stringIDToTypeID("spot"), true);
d.putBoolean(stringIDToTypeID("alphaChannels"), true);
d.putBoolean(stringIDToTypeID("layers"), true);
d.putBoolean(stringIDToTypeID("embedProfiles"), true);
d.putBoolean(stringIDToTypeID("annotType"), true);
executeAction(stringIDToTypeID("save"), d, DialogModes.NO);
} catch(e) { alert(e); }
Copy link to clipboard
Copied
This also works very well, same question I suppose how I would stop it making an endless amount of sub-folders and just continue to save in the sub-folder initially created?
Copy link to clipboard
Copied
No chains should be created. Explain what you are saving at least on the example of two files (two script calls).
Copy link to clipboard
Copied
Apologies in advance if I'm not as concise with my description. So, if I continue to use the script (two script calls), is there a way it to act as a standard save function after the first run of the script and creation of the sub-folder/psb file? If not, it's not vital
Copy link to clipboard
Copied
if (activeDocument.path.fsName.search(/[\/\\]Edits$/i) >= 0)
{
var file = activeDocument.fullName;
}
else
{
var folder = new Folder(activeDocument.path.fsName + "/Edits"); if (!folder.exists) folder.create();
var file = new File(folder.fsName + "/" + activeDocument.name);
}
var d = new ActionDescriptor();
var d1 = new ActionDescriptor();
d1.putBoolean(stringIDToTypeID("maximizeCompatibility"), false);
d.putObject(stringIDToTypeID("as"), stringIDToTypeID("largeDocumentFormat"), d1);
d.putPath(stringIDToTypeID("in"), file);
d.putBoolean(stringIDToTypeID("copy"), false); // false == save NOT A copy of current document
d.putBoolean(stringIDToTypeID("spot"), true);
d.putBoolean(stringIDToTypeID("alphaChannels"), true);
d.putBoolean(stringIDToTypeID("layers"), true);
d.putBoolean(stringIDToTypeID("embedProfiles"), true);
d.putBoolean(stringIDToTypeID("annotType"), true);
executeAction(stringIDToTypeID("save"), d, DialogModes.NO);