Thanks for the approach.
I'm not sure how to convert actions .atn to .jsx
Is there a link for showing how to do this?
I couldn't find anything online.
Thanks for the approach.
I'm not sure how to convert actions .atn to .jsx
Is there a link for showing how to do this?
I couldn't find anything online.
You either just call the action, as shown above, using the doAction() method, or you note step by step of the action, and repeat them manually while the ScriptListener plug-in is active. Then you take its output and clean it up and turn it into a function.
A trick, which did help me a lot with cleaning up is to open the ScriptListener log in the ExtendScript Toolkit, and let it display its update after each and every step you do, and note the desc number of the last step.
Hi,
Im completely new to using Lightroom/Photoshop and have been directed to this thread from elsewhere.
Basically I want to be able to batch resize a number of images (jpeg) so that they are under 2mb in size, we currently use a programme called 'Fotosizer' (www.fotosizer.com), this allows us to reduce the image by a % whilst claiming to lose none of the quality. Is this a safe way to continue of should we be looking to do this in Lightroom/Photoshop and if thats the case how would we go about doing so baring in mine we are complete newbies.
Thanks for any help!
Another option is xbytor’s xtools:
ps-scripts - Browse /xtools/v2.3 at SourceForge.net
https://www.ps-scripts.com/viewforum.php?f=53
ActionFileToJavascript.jsx
ActionToJavascript.jsx
I found an old post by Mike Hale showing how to get the total frame count which works. I tried applying this same method to get the frame rate and the current frame hours, seconds, minutes and frame. The frame rate function works but not the hours,minutes,second and frame. I think those link to "timecode" instead of "timeline". The script listener function to goto a specific timecode works. I was trying to piece together AM code to get the current the hours, minutes, seconds and frame based on the info in the script listener code but. I tried MANY combinations of things but couldn't get anything to work. Honestly, I have a hard time wrapping my brain around AM code.
Any ideas on how to get the hours,minutes,seconds and frame functions to work?
function getTotalFrameCount(){
var ref = new ActionReference();
ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "frameCount" ) );
ref.putClass( stringIDToTypeID( "timeline" ) );
var desc = new ActionDescriptor();
desc.putReference( charIDToTypeID( "null" ), ref );
var resultDesc = executeAction( charIDToTypeID( "getd" ), desc, DialogModes.NO );
return resultDesc.getInteger( stringIDToTypeID( "frameCount" ) );
}
function getFrameRate(){
var ref = new ActionReference();
ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "frameRate" ) );
ref.putClass( stringIDToTypeID( "timeline" ) );
var desc = new ActionDescriptor();
desc.putReference( charIDToTypeID( "null" ), ref );
var resultDesc = executeAction( charIDToTypeID( "getd" ), desc, DialogModes.NO );
return resultDesc.getDouble( stringIDToTypeID( "frameRate" ) );
}
function getFrameHours(){
var ref = new ActionReference();
ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "hours" ) );
ref.putClass( stringIDToTypeID( "timeline" ) );
var desc = new ActionDescriptor();
desc.putReference( charIDToTypeID( "null" ), ref );
var resultDesc = executeAction( charIDToTypeID( "getd" ), desc, DialogModes.NO );
return resultDesc.getInteger( stringIDToTypeID( "hours" ) );
}
function getFrameMinutes(){
var ref = new ActionReference();
ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "minutes" ) );
ref.putClass( stringIDToTypeID( "timeline" ) );
var desc = new ActionDescriptor();
desc.putReference( charIDToTypeID( "null" ), ref );
var resultDesc = executeAction( charIDToTypeID( "getd" ), desc, DialogModes.NO );
return resultDesc.getInteger( stringIDToTypeID( "minutes" ) );
}
function getFrameSeconds(){
var ref = new ActionReference();
ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "seconds" ) );
ref.putClass( stringIDToTypeID( "timeline" ) );
var desc = new ActionDescriptor();
desc.putReference( charIDToTypeID( "null" ), ref );
var resultDesc = executeAction( charIDToTypeID( "getd" ), desc, DialogModes.NO );
return resultDesc.getInteger( stringIDToTypeID( "seconds" ) );
}
function getFrame(){
var ref = new ActionReference();
ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "frame" ) );
ref.putClass( stringIDToTypeID( "timeline" ) );
var desc = new ActionDescriptor();
desc.putReference( charIDToTypeID( "null" ), ref );
var resultDesc = executeAction( charIDToTypeID( "getd" ), desc, DialogModes.NO );
return resultDesc.getInteger( stringIDToTypeID( "frame" ) );
}
function goToFrame(h,m,s,f,r){
var idsetd = charIDToTypeID( "setd" );
var desc14 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idPrpr = charIDToTypeID( "Prpr" );
var idtime = stringIDToTypeID( "time" );
ref2.putProperty( idPrpr, idtime );
var idtimeline = stringIDToTypeID( "timeline" );
ref2.putClass( idtimeline );
desc14.putReference( idnull, ref2 );
var idT = charIDToTypeID( "T " );
var desc15 = new ActionDescriptor();
var idhours = stringIDToTypeID( "hours" );
desc15.putInteger( idhours, h );
var idminutes = stringIDToTypeID( "minutes" );
desc15.putInteger( idminutes, m );
var idseconds = stringIDToTypeID( "seconds" );
desc15.putInteger( idseconds, s );
var idframe = stringIDToTypeID( "frame" );
desc15.putInteger( idframe, f );
var idframeRate = stringIDToTypeID( "frameRate" );
desc15.putDouble( idframeRate, r );
var idtimecode = stringIDToTypeID( "timecode" );
desc14.putObject( idT, idtimecode, desc15 );
executeAction( idsetd, desc14, DialogModes.NO );
}
One more question. The script saves the file as 85,1MB, while usually saving makes it about 8MB, could anything be done to that?
Seems like what it needs is to use compression Smallest / Slow , but i dont know how to set that in the script, currently uses none
good morning
the web I found a script for after effects
unfortunately it does not work in photoshop
do you think can be adapted for Photoshop
or are two different languages.
I've been trying to find a way to retrieve the timecode data for hours, minutes, seconds and frame for the current position in a Video in Photoshop. The script listener will record when the current active frame is changed. I can't seem to piece together anyway to get the data.
I've spent all day trying to figure this out. Any action manager coding experts out there that know how to do this?
This is the script listener code it gives when changing the current active frame. I figured this info could be used to make function to get the data.
// ======================================================= var idsetd = charIDToTypeID( "setd" ); var desc405 = new ActionDescriptor(); var idnull = charIDToTypeID( "null" ); var ref80 = new ActionReference(); var idPrpr = charIDToTypeID( "Prpr" ); var idtime = stringIDToTypeID( "time" ); ref80.putProperty( idPrpr, idtime ); var idtimeline = stringIDToTypeID( "timeline" ); ref80.putClass( idtimeline ); desc405.putReference( idnull, ref80 ); var idT = charIDToTypeID( "T " ); var desc406 = new ActionDescriptor(); var idhours = stringIDToTypeID( "hours" ); desc406.putInteger( idhours, 1 ); var idminutes = stringIDToTypeID( "minutes" ); desc406.putInteger( idminutes, 2 ); var idseconds = stringIDToTypeID( "seconds" ); desc406.putInteger( idseconds, 57 ); var idframe = stringIDToTypeID( "frame" ); desc406.putInteger( idframe, 29 ); var idframeRate = stringIDToTypeID( "frameRate" ); desc406.putDouble( idframeRate, 29.970000 ); var idtimecode = stringIDToTypeID( "timecode" ); desc405.putObject( idT, idtimecode, desc406 ); executeAction( idsetd, desc405, DialogModes.NO );
Also, the 2 functions below work for getting the total frame count and frame rate. I found an old posting by Mike Hale showing how to get the total frame count and I was able to use the same method to get the frame rate as well. However, using the same method doesn't seem to work for the hours, minutes, seconds and frame. I have tried dozens of ways to patch together AM code to do it. I'm guess that it is possible but I just don't understand action manager code well enough to figure it out.
These functions work for frame count and frame rate...
function getTotalFrameCount(){ var ref = new ActionReference(); ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "frameCount" ) ); ref.putClass( stringIDToTypeID( "timeline" ) ); var desc = new ActionDescriptor(); desc.putReference( charIDToTypeID( "null" ), ref ); var resultDesc = executeAction( charIDToTypeID( "getd" ), desc, DialogModes.NO ); return resultDesc.getInteger( stringIDToTypeID( "frameCount" ) ); } function getFrameRate(){ var ref = new ActionReference(); ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "frameRate" ) ); ref.putClass( stringIDToTypeID( "timeline" ) ); var desc = new ActionDescriptor(); desc.putReference( charIDToTypeID( "null" ), ref ); var resultDesc = executeAction( charIDToTypeID( "getd" ), desc, DialogModes.NO ); return resultDesc.getDouble( stringIDToTypeID( "frameRate" ) ); }
How would we have any idea? Given the information you posted we have not Idea of what you found or what it does. Photoshop also onle supports some basin video editing. AE is more a video edotor than PS.
Supply pertinent information for quicker answers
JJMack you're absolutely right
the script and a launcher that works this way
once started you select the folder where the file .jsx
automatically loading in the dialog window ui
This and the script:
// rd_ScriptLauncher.jsx
// Copyright (c) 2005-2013 redefinery (Jeffrey R. Almasol).
// rd_ScriptLauncher()
//
// Description:
// This function contains the main logic for this script.
//
// Parameters:
// thisObj - "this" object.
//
// Returns:
// Nothing.
//
(function rd_ScriptLauncher(thisObj)
{
// Globals
var rd_ScriptLauncherData = new Object(); // Store globals in an object
rd_ScriptLauncherData.scriptName = "rd: Script Launcher";
rd_ScriptLauncherData.scriptTitle = rd_ScriptLauncherData.scriptName + " v3.1";
rd_ScriptLauncherData.scriptPath = "";
rd_ScriptLauncherData.scriptFiles = new Array();
rd_ScriptLauncherData.strScriptsFolder = {en: "Folder..."};
rd_ScriptLauncherData.strShowPaths = {en: "Show paths"};
rd_ScriptLauncherData.strRefreshList = {en: "Refresh"};
rd_ScriptLauncherData.strRun = {en: "Run"};
rd_ScriptLauncherData.strHelp = {en: "?"};
rd_ScriptLauncherData.strErrNoScriptsPath = {en: "Cannot open the palette because the Scripts folder could not be located."};
rd_ScriptLauncherData.strErrMissingFile = {en: "Cannot locate the selected script."};
rd_ScriptLauncherData.strMinAE100 = {en: "This script requires Adobe After Effects CS5 or later."};
rd_ScriptLauncherData.strHelpText =
{
en: "Copyright (c) 2005-2013 redefinery (Jeffrey R. Almasol). \n" +
"All rights reserved.\n" +
"\n" +
"This script displays a palette of the installed scripts in the selected Scripts folder (and subfolders). Only scripts with .js, .jsx, and .jsxbin extensions are displayed. Double-click a script to launch it. Double-click a script to launch it. Scripts located in subfolders whose names are enclosed in parentheses are ignored. You can change the Scripts folder at any time, and refresh the scripts list if the contents of the folder have changed. The selected scripts folder is stored as a setting, so you don't have to reselect it every time you reopen this palette.\n" +
"\n" +
"Note: The palette cannot detect any errors in the scripts that you run from it. It's just a quick way of launching scripts without restarting AE or using ExtendScript Toolkit (i.e., switching away from AE).\n" +
"\n" +
"If a PNG file of a similar name and same folder as the script file (but with a .png file name extension) exists, it will appear next to the script name in the list.\n" +
"\n" +
"Note: This version of the script requires After Effects CS5 or later. It can be used as a dockable panel by placing the script in a ScriptUI Panels subfolder of the Scripts folder, and then choosing this script from the Window menu.\n" +
"\n" +
"Enhancements requested by Russ Maehl, Julian Herrera, and Navarro Parker."
};
// rd_ScriptLauncher_localize()
//
// Description:
// This function localizes the given string variable based on the current locale.
//
// Parameters:
// strVar - The string variable's name.
//
// Returns:
// String.
//
function rd_ScriptLauncher_localize(strVar)
{
return strVar["en"];
}
// rd_ScriptLauncher_buildUI()
//
// Description:
// This function builds the user interface.
//
// Parameters:
// thisObj - Panel object (if script is launched from Window menu); null otherwise.
//
// Returns:
// Window or Panel object representing the built user interface.
//
function rd_ScriptLauncher_buildUI(thisObj)
{
var positionPal = (app.settings.haveSetting("redefinery", "rd_ScriptLauncher_frameBounds") && !(thisObj instanceof Panel));
if (positionPal)
{
var bounds = new Array();
bounds = app.settings.getSetting("redefinery", "rd_ScriptLauncher_frameBounds").split(",");
for (i in bounds)
bounds[i] = parseInt(bounds[i], 10);
}
else
var bounds = undefined;
var pal = (thisObj instanceof Panel) ? thisObj : new Window("palette", rd_ScriptLauncherData.scriptName, bounds, {resizeable:true});
if (pal !== null)
{
var res =
"group { \
orientation:'column', alignment:['fill','fill'], \
header: Group { \
alignment:['fill','top'], \
title: StaticText { text:'" + rd_ScriptLauncherData.scriptName + "', alignment:['fill','center'] }, \
help: Button { text:'" + rd_ScriptLauncher_localize(rd_ScriptLauncherData.strHelp) +"', maximumSize:[30,20], alignment:['right','center'] }, \
}, \
listBox: ListBox { alignment:['fill','fill'], properties:{items:" + rd_ScriptLauncherData.scripts + "} }, \
footer: Group { \
alignment:['fill','bottom'], \
folder: Button { text:'" + rd_ScriptLauncher_localize(rd_ScriptLauncherData.strScriptsFolder) + "', alignment:['left','center'], preferredSize:[-1,20] }, \
showPaths: Checkbox { text:'" + rd_ScriptLauncher_localize(rd_ScriptLauncherData.strShowPaths) + "', alignment:['left','bottom'], value:true }, \
refresh: Button { text:'" + rd_ScriptLauncher_localize(rd_ScriptLauncherData.strRefreshList) + "', alignment:['right','center'], preferredSize:[-1,20] }, \
}, \
}";
pal.grp = pal.add(res);
pal.grp.listBox.preferredSize.height = 300;
pal.layout.layout(true);
pal.grp.minimumSize = [pal.grp.size.width, pal.grp.header.size.height + pal.grp.spacing * 5];
pal.layout.resize();
pal.onResizing = pal.onResize = function () {this.layout.resize();}
pal.grp.header.help.onClick = function () {alert(rd_ScriptLauncherData.scriptTitle + "\n" + rd_ScriptLauncher_localize(rd_ScriptLauncherData.strHelpText), rd_ScriptLauncherData.scriptName);}
pal.grp.footer.folder.onClick = rd_ScriptLauncher_doSelectFolder;
pal.grp.footer.refresh.onClick = rd_ScriptLauncher_doRefreshList;
pal.grp.listBox.onDoubleClick = rd_ScriptLauncher_doRun;
pal.grp.footer.showPaths.onClick = function ()
{
rd_ScriptLauncher_buildScriptsList(pal);
}
}
return pal;
}
// rd_ScriptLauncher_doSelectFolder()
//
// Description:
// This callback function asks the user to locate the Scripts folder.
//
// Parameters:
// None.
//
// Returns:
// Nothing.
//
function rd_ScriptLauncher_doSelectFolder()
{
var folder = Folder.selectDialog("Locate AE's Scripts folder");
if (folder !== null)
{
rd_ScriptLauncherData.scriptPath = folder;
// Store the path in the settings so the user doesn't have to set it the next time
app.settings.saveSetting("redefinery", "rd_ScriptLauncher_scriptPath", folder.fsName)
rd_ScriptLauncher_buildScriptsList(this.parent.parent.parent);
}
}
// rd_ScriptLauncher_doRefreshList()
//
// Description:
// This callback function rescans the current Scripts folder and
// rebuilds the scripts list.
//
// Parameters:
// None.
//
// Returns:
// Nothing.
//
function rd_ScriptLauncher_doRefreshList()
{
rd_ScriptLauncher_buildScriptsList(this.parent.parent.parent);
}
// rd_ScriptLauncher_doRun()
//
// Description:
// This callback function runs the selected script.
//
// Parameters:
// None.
//
// Returns:
// Nothing.
//
function rd_ScriptLauncher_doRun()
{
var scriptSelected = (rdslPal.grp.listBox.selection !== null);
if (scriptSelected)
{
var scriptIndex = rdslPal.grp.listBox.selection.index;
var scriptFile = new File(rd_ScriptLauncherData.scriptFiles[scriptIndex].absoluteURI);
// Load the script's contents into a string
/*
if (scriptFile.fsName.match(/.jsxbin$/) === null)
{
var scriptText = "";
// Load the script's contents into a string
scriptFile.open("r");
while (!scriptFile.eof)
scriptText += scriptFile.readln() + "\r\n";
scriptFile.close();
// Evaluate the script's contents
eval(scriptText);
}
else
$.evalFile(scriptFile);
*/
if (scriptFile.exists)
$.evalFile(scriptFile);
else
alert(rd_ScriptLauncher_localize(rd_ScriptLauncherData.strErrMissingFile), rd_ScriptLauncherData.scriptName);
}
}
// rd_ScriptLauncher_sortByName()
//
// Description:
// Custom array sort function for sorting File and Folder objects by their names.
//
// Parameters:
// a - First object.
// b - Second object.
//
// Returns:
// Integer controlling the array sort function.
//
function rd_ScriptLauncher_sortByName(a, b)
{
if (a.name.toLowerCase() < b.name.toLowerCase())
return -1;
else if (a.name.toLowerCase() > b.name.toLowerCase())
return 1;
else
return 0;
}
// rd_ScriptLauncher_getAEScripts()
//
// Description:
// This callback function retrieves the list of scripts.
//
// Parameters:
// path - Folder object of the folder to scan.
//
// Returns:
// Array of FileSystem objects.
//
function rd_ScriptLauncher_getAEScripts(path)
{
var pathFiles = path.getFiles(), files = new Array(), subfiles;
// Sort the entries in pathFiles
pathFiles.sort(rd_ScriptLauncher_sortByName);
// Loop through the current folder's files and subfolders
for (var i = 0; i < pathFiles.length; i++)
if (pathFiles[i] instanceof Folder)
{
// Skip recusion if folder's name is enclosed in parentheses
if (pathFiles[i].name.match(/^\(.*\)$/))
continue;
else
{
// Recurse, and append contents - isn't there an easier way, like array addition?
subfiles = rd_ScriptLauncher_getAEScripts(pathFiles[i]);
for (var j = 0; j < subfiles.length; j++)
files[files.length] = subfiles[j];
}
}
else
{
// Add only files that end in .js or .jsx or .jsxbin, and that isn't this file itself
if (pathFiles[i].name.match(/\.(js|jsx|jsxbin)$/) && (pathFiles[i].fsName !== File($.fileName).fsName))
files[files.length] = pathFiles[i];
}
return files;
}
// rd_ScriptLauncher_buildScriptsList()
//
// Description:
// This function builds the contents of the scripts list.
//
// Parameters:
// palette - Window object.
//
// Returns:
// Nothing.
//
function rd_ScriptLauncher_buildScriptsList(palette)
{
var fullName, script;
// Remove the existing list items
palette.grp.listBox.removeAll();
// Load the scripts from the Scripts folder hierarchy
rd_ScriptLauncherData.scriptFiles = rd_ScriptLauncher_getAEScripts(rd_ScriptLauncherData.scriptPath);
var item, iconFile;
for (var i = 0; i < rd_ScriptLauncherData.scriptFiles.length; i++)
{
// Build the array of script names used in the UI, but strip off the base path
// (and folder separator, assumed as one character)
fullName = rd_ScriptLauncherData.scriptFiles[i].fsName;
iconFile = File(fullName.replace(/.(js|jsx|jsxbin)$/,".png"));
if (palette.grp.footer.showPaths.value === true)
fullName = fullName.substr(rd_ScriptLauncherData.scriptPath.fsName.length+1);
else
fullName = rd_ScriptLauncherData.scriptFiles[i].displayName;
// Add the script's name to the list box
item = palette.grp.listBox.add("item", fullName);
if (iconFile.exists)
item.icon = iconFile;
}
}
// main code:
//
// Prerequisites check
if (parseFloat(app.version) < 10.0)
alert(rd_ScriptLauncher_localize(rd_ScriptLauncherData.strMinAE100), rd_ScriptLauncherData.scriptName);
else
{
// Check if the script path variable is stored in the settings; use if so
var gotScriptPath = false;
if (app.settings.haveSetting("redefinery", "rd_ScriptLauncher_scriptPath"))
{
rd_ScriptLauncherData.scriptPath = new Folder(app.settings.getSetting("redefinery", "rd_ScriptLauncher_scriptPath"));
gotScriptPath = true;
}
else
{
// No stored script path, so ask the user where the Scripts folder is located
var folder = Folder.selectDialog("Locate AE's Scripts folder");
if (folder !== null)
{
rd_ScriptLauncherData.scriptPath = folder;
gotScriptPath = true;
// Store the path in the settings so the user doesn't have to set it the next time
app.settings.saveSetting("redefinery", "rd_ScriptLauncher_scriptPath", folder.fsName)
}
}
// Build and show the palette
var rdslPal= rd_ScriptLauncher_buildUI(thisObj);
if (rdslPal !== null)
{
if (app.settings.haveSetting("redefinery", "rd_ScriptLauncher_showPaths"))
rdslPal.grp.footer.showPaths.value = (app.settings.getSetting("redefinery", "rd_ScriptLauncher_showPaths") === "false") ? false : true;
if (gotScriptPath)
rd_ScriptLauncher_buildScriptsList(rdslPal);
else
alert(rd_ScriptLauncher_localize(rd_ScriptLauncherData.strErrNoScriptsPath), rd_ScriptLauncherData.scriptName);
rdslPal.onClose = function()
{
app.settings.saveSetting("redefinery", "rd_ScriptLauncher_showPaths", rdslPal.grp.footer.showPaths.value);
if (!(rdslPal instanceof Panel))
app.settings.saveSetting("redefinery", "rd_ScriptLauncher_frameBounds", rdslPal.frameBounds.toString());
}
if (rdslPal instanceof Window)
{
//rdslPal.center();
rdslPal.show();
}
else
rdslPal.layout.layout(true);
}
}
})(this);
I have the following (supposedly simple) JSX code that I run after creating a new blank Photoshop document:
var meta = app.activeDocument.activeLayer.xmpMetadata $.writeln(meta.rawData)
However, for some reason, the only thing I can get out of this is an error on the second line saying "'value' property is missing". Even trying to view the object contents with the ESTK Data Browser makes it break (it cannot display more than the "parent" field, after that it shows the same error in the Data Browser itself).
However, if I try to set the `meta.rawData` field to some random string before trying to read it in any way, it works (well, I get back my own string). Obviously, this is not a valid solution, as I want to read the field before setting it to anything else.
Does anyone know if this is a bug (it certainly looks like it!) and how to workaround it?
Thanks in advance
Put the read into try-catch. If it throws an error the key isn't exists yet. If you set it, then write, close, reopen the .psd, the value will be there.
Hello. I need some help. I'm using Photoshop CC 2015.
Here is a look at my layer groups. Contact Information and Pricing are my two Top Level Layer Groups. Below those you will see sub layers of locations and pricing tiers.
I am trying to automate to process of exporting every permutation of Contact Information and Pricing as a pdf.
I am half way to my ideal solution by using the below piece of code that I found elsewhere in the forums.
Problem #1: Using this code I can keep one Layer Group constant and cycle through permutations of second Layer Group. So if I select Platinum from the Pricing group, it will return all of the Contact Information layers for Platinum. But then it stops. I want to modify the code so that when it's done with Platinum, it moves on to the next layer and returns all permutations for Gold, then Silver then Standard. So basically I need a loop within a loop.
Problem #2: The saved pdf file size is way too big, 30MB. I created a Save Preference in Adobe and called it Binder. I tried to plug that preference into the script, but I cant get it to pick up.
Thanks all
__________________________________________________________________________________________ ________________________________________
// Name: Export Layers Inside Selected Group.jsx
// Description: Photoshop script that separately saves top level layers inside the selected group.
// https://gist.github.com/joonaspaakko/013a223e94ba0fb9a2a0
#target photoshop
try {
var doc = app.activeDocument;
var docName = doc.name.split('.')[0];
}
catch (e) {
alert( 'Open a document first...' );
}
function init() {
var savefiles;
dlg.g.saveAs.minimumSize.width = 463;
dlg.btns.minimumSize.height = 142;
dlg.btns.save.onClick = function(){
savefiles = true;
dlg.close();
return savefiles;
};
dlg.show();
if ( savefiles ){
var getDestination = Folder.selectDialog( 'Select destination folder...', doc.saved ? doc.path : '' );
var group = doc.activeLayer;
var groupLength = group.layers.length;
for( var i = 0 ; i < groupLength; i++ ){
group.layers[i].visible = false;
}
for( var i = 0 ; i < groupLength; i++ ){
var layer = group.layers[ i ];
var layerIndex = i+1;
layer.visible = true;
save.file( dlg, doc, getDestination, layerIndex );
layer.visible = false;
}
alert('Files Saved!');
}
}
var save = {
file: function( dlg, doc, getDestination, layerIndex ) {
var saveOptions = {};
var formats = ["psd", "pdf", "png", "jpg", "tiff"];
for ( var i=0; i < formats.length; i++ ) {
if ( dlg.g.saveAs[ formats[i] ].value ) {
var fileformat = formats[i];
var path = getDestination + "/" + fileformat;
makeFolder( path );
doc.saveAs( File( path + "/" + dlg.g.filename.filename.text + activeDocument.activeLayer.layers[layerIndex-1].name ), save[fileformat](), true );
}
}
},
psd: function() {
var psd_saveOpts = new PhotoshopSaveOptions();
psd_saveOpts.layers = true;
psd_saveOpts.embedColorProfile = true;
psd_saveOpts.annotations = true;
psd_saveOpts.alphaChannels = true;
return psd_saveOpts;
},
pdf: function() {
var presetName = '[Binder]';
var pdf_SaveOpts = new PDFSaveOptions();
pdf_SaveOpts.pDFPreset = presetName;
return pdf_SaveOpts;
},
jpg: function() {
var jpg_SaveOpts = new JPEGSaveOptions();
jpg_SaveOpts.matte = MatteType.WHITE;
jpg_SaveOpts.quality = 10;
jpg_SaveOpts.formatOptions.STANDARDBASELINE;
return jpg_SaveOpts;
},
png: function() {
var png_SaveOpts = new PNGSaveOptions();
png_SaveOpts.compression = 9;
png_SaveOpts.interlaced = false;
return png_SaveOpts;
},
tiff: function() {
var tiff_SaveOpts = new TiffSaveOptions();
tiff_SaveOpts.alphaChannels = true;
tiff_SaveOpts.annotations = true;
tiff_SaveOpts.imageCompression = TIFFEncoding.JPEG;
tiff_SaveOpts.interleaveChannels = true;
tiff_SaveOpts.jpegQuality = 10;
tiff_SaveOpts.layers = true;
tiff_SaveOpts.layerCompression = LayerCompression.ZIP;
tiff_SaveOpts.transparency = true;
return tiff_SaveOpts;
}
};
// Prepare dialog...
var dlg = new Window("dialog { \
text: 'Export layers inside the selected group', \
alignChildren:['left','center'], \
orientation: 'row', \
g: Group { \
orientation:'column', \
alignChildren: ['left','center'], \
filename: Panel { \
orientation:'column', \
alignChildren: ['left','top'], \
filename_text: StaticText { alignment:'left', text: 'Filename ( Incremental numbers added automatically ): '}, \
filename: EditText { alignment:'left', preferredSize: [430,20], text: '"+ docName +"', active: true }, \
}, \
saveAs: Panel { \
margins: 20, \
spacing: 20, \
orientation: 'row', \
alignChildren: ['left','top'], \
saveAs_txt: StaticText { text: 'Save as: '}, \
jpg: Checkbox { text: 'jpg', value: true }, \
psd: Checkbox { text: 'psd', value: false }, \
pdf: Checkbox { text: 'pdf', value: false }, \
png: Checkbox { text: 'png', value: false }, \
tiff: Checkbox { text: 'tiff', value: false } \
} \
}, \
btns: Panel { \
margins: 20, \
spacing: 20, \
orientation: 'column', \
alignment: ['right','top'], \
save: Button { text: 'Save', properties:{ name: 'ok' }, preferredSize:[88, 24] }, \
cancel: Button { text: 'Cancel', properties:{ name: 'cancel' }, preferredSize:[88, 24] }, \
} \
}");
function makeFolder( path ) {
var newFolder = Folder( path );
if( !newFolder.exists ) newFolder.create();
}
if ( app.documents.length > 0 ) {
if ( app.activeDocument.activeLayer.layers ) {
init();
}
else {
alert( "Error: \nSelect a parent group of the layers you want to export.")
}
}
I have about 1000 folders, with one or two PSD's in each. Each PSD has the cutout product photography from different angles, but they are sitting on top of each other so I didn't have to save multiple PSD's for each picture. I now need to resize each picture(layer) to be 3000x3000px at 72dpi. This would take me about 2 weeks if I was to do each one individually.
Parent Folder (example)
Goal – Run batch of Parent folder and it would open each PSD, move each layer to a new document, crop to square, resize to 3000x3000 and save the .JPG to the accompanying Child Folder ideally with the original name of the childfolder-SKU_#1.jpg
I created two Actions to do this.
What is your final workflow? You press F1 to move back 1 frame and the layer at the playhead is also selected? F2 to move forward and select that frame?
How are 2-exposure frames handled? Does the selected layer and the playhead get out of sync?
Thanks for figuring this out.
@SuperMerlin, Does your link still work? The file is a .vi file. I don't see the .zip.
Could you please post the original file again? I'd really appreciate it.
Thanks!
That sounds like one of my favorite Photoshop extension. Have you ever use Photoshop menu Help>Find Plug-ins and Extensions....
It may not be the one I found and use all the time. The one I found is names JSX Launcher I doe not think that one supports JSXbin or JS files. It may I never tried adding in any .JS or .sxbin file.
I cringe when I read appends like your. Actions can not use logic so the can not determine how many file are in a folder and can nor find out how many layer are in a psd document. Action also have a very hard time saving multiple different named files for a document it is processing. When I see 3000x3000px @ 72DIP it make no sense for you do not Print a 3000x3000px image 72DPI, 41.6" x 41.6" low resolution for what. Also 3000px x 3000px will not even fit on a 4k 3860px x 2160px Display.
You need to script you whole process and for best image quality do not interpolate an image more than once. Think more about what you want to do. Then design a process that will work. Cutouts have transparency. Object from different angles will result in layer with diffener bound aspect ratios and the object may not be center over the document canvas. You need to deride what kine of output image you need. What the images composition will be the you produce..
you may want to start with the Image Processor script or the better download Image Processor Pro script to process your Images tree. To process all your image folders.
Yeah, I forgot to say that this is exactly what I'm doing right now, but it still feels like a bug?