Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

PSB Save Script with activeDocument.path and sub-folder

Community Beginner ,
May 03, 2023 May 03, 2023

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. 

TOPICS
Actions and scripting , macOS
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , May 03, 2023 May 03, 2023
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
...
Translate
Adobe
Community Beginner ,
May 03, 2023 May 03, 2023

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 );
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 03, 2023 May 03, 2023

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);

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 03, 2023 May 03, 2023

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? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 03, 2023 May 03, 2023

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); }

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 03, 2023 May 03, 2023

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? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 03, 2023 May 03, 2023

No chains should be created. Explain what you are saving at least on the example of two files (two script calls).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 03, 2023 May 03, 2023

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 03, 2023 May 03, 2023
LATEST
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);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines