Skip to main content
Participating Frequently
January 28, 2019
Question

Running a script within an action

  • January 28, 2019
  • 6 replies
  • 12529 views

I'm trying to achieve a very specific, easy but time consuming task with Photoshop, but I'm very much a beginner to the action / scripting side of things, my only frame of reference is that it might be like Macros in Excel. Mainly I was hoping to run a couple of ideas past the forum, and some expert might be able to tell me if I'm barking up the wrong tree, or if I'm onto something.

I've got to put labels on jars of sweets using Photoshop. I've got 30-odd varieties of sweets, each with 3 different sized jars, and 40-odd labels.

What I've done so far is put all of my labels into a Smart Object. This allows me to warp the labels around my jar naturally. I've then put every iteration of the jars in my Photoshop document. I've made every iteration into a group, and within each group I've put a copy of the Smart Object label, perfectly placed over the jar.

I've found a bit of script that will then take every group, and save it as a jpg in a file of my choosing.

The time consuming bit is that every . time the script runs, I then have to go to the Smart Object, turn off the top layer, to reveal the next label, and then run the script again. That sounds like a quick process, but the file is so big now, that it takes about 10 minutes just to save the Smart Object, and update the 120-odd instances of the Smart Object, then it takes another 10 minutes for the script to save 90-odd jpgs. And I've got to do this for 41 labels, with 50-odd more coming each month.

I was hoping I might be able to create an action that goes into the smart object, finds the next visible layer and turns it off, copies the name of the layer, saves the Smart Object, runs the script, uses the copied name as a file extension, and then repeats until it's run out of visible rows. Then it can take as long as it wants, and I can leave it running overnight.

Does that sound possible? Is it there a more efficient way of achieving the same result?

Thanks in advance.

This topic has been closed for replies.

6 replies

Known Participant
October 20, 2023

Mockup image creation is a very simple thing to automate using the Batch Replace Smart Objects plugin for Photoshop. Basically, just select the Photoshop document to use (in this case, your mockup images of the jar which contains the Smart Object), the input folder of your images (in this case, your label designs), then the output folder to save the final images to.

 

However in your specific case, note that I don't think this plugin will work for complex .psd documents that have multiple Smart Objects that all need to be replaced. Like, if you have a Photoshop document with 2 or 3 jars, and you want all 3 of the jars updated simultaneously with the one artwork images or label design? I don't think this plugin will work. I've only used it for mockup images with one single Smart Object that needs to be replaced with images (such as apparel mockups featuring one hoodie, or wall art mockups featuring one art piece.)

 

If you're doing something super complex and customized like that, really I don't think there is ANY kind of pre-built template script or software that can do that for you. Something that highly customized will almost certainly require a separate, standalone .jsx script that's specifically built for the exact workflow and set of Photoshop documents you're using. There was another guy on these forums who posted a similar question inquiring about how to batch-generate mockups when the .psd documents contain 4 separate wall art mockups -- each needing to use 4 different artworks designs, grouped together in sequence but iterated through as groups of 4. Like if you're doing THAT level of complexity, the only answer is a custom script designed for that exact unique workflow.

 

If possible for what you're doing, it'd be way easier to simplify your workflow + stick to just one mockup at a time. That way, you could just use a Photoshop plugin or simpler .jsx script to automate it by iterating through all images in your input folder. Is it absolutely mission critical that you create product images featuring 3 jars instead of 1? Do you have any valid reason to believe that your conversion rate will substantially drop if the product photos feature just 1 jar instead of 3 side-by-side like that? Not trying to be a smartass, but honestly, you might be very needlessly overcomplicating things just to try to create a much more complex image when a much simpler image will be exactly as effective at driving conversions, satisfying the client, or doing whatever it is that you're trying to do. I would honestly ask yourself: "Would a simpler mockup automation workflow be exactly as effective for achieving my ultimate goals here? If so, why am I making things so much more complicated than they need to be?"

 

This more complex stuff -- I mean if you don't know how to write the .jsx scripts yourself, you'll probably have to hire a freelancer who specializes in Photoshop automation to do it for you. (You can find some on Upwork if needed -- just search Photoshop automation or Photoshop scripting or something like that.)

JJMack
Community Expert
February 12, 2019

Photoshop cc 2019 doing some strange things;  I redid all the templates and labels.  I had left the 41 label layer in the templates smart object. So I remove all but one and changed the one remaining label opacity to zero so it would not be visible in the templates.  I change all the label file format from png to psd for when I have edited png objects the save took a long time.  The smart object is your template was created in photoshop from a raster layer so when it is opened in Photoshop.  Photoshop creates a PSB work file for the object. So PSD in more in line with psb.  CS6 did not fail. CC 2019 fails consistently populating the 04LM mockup when batched with all 84 mockups but not in the same place.  It does not fail if I just populate the 04LM template or all the mockup before 0LM4 and 04LM.   When I saved PSD as well I notice the jpeg files have the wrong date. The PSD files have today's date the jpg yesterdays date.  In the 04LM Output PSD files, the last PSD with two alike labels is messed up though it looks correct it must have been where the replace content was canceled by the user. All the  04LM PSD file after the only have the small label updated.  If I try to update the last PSD with two identical labels the update of the object fails with a program error. If I try a second time there is no program error, however only the small jar label layer updates.  CC 2019 has some issues and the kind the will be very hard for Adobe to track down and fix.   

CC 2018 seems to hang if I leave the machine alone. When I come back and play with the mouse CC 2018 seem t0 get out of its funk and continues to populate templates.

I testing CC 2019 at this moment batching all 84 templates it has passed the 04LM template this time without the user canceled operation error I think it is going to be very hard for Adobe to track down.

JJMack
JJMack
Community Expert
February 13, 2019

The fourth time CC 2019 ran without error. It took my machine around 1 and 1/2 hour to populate the 84 Templates with the 41 replacement labels. My machine is only 2 GHZ slow it has 40GB Ran and two 6core xeons.  Photoshop only seems to be single threaded only one processor thread was  pegged. The other 23 were mostly idle. I was saving ]both PSD and JPG files. so 6,888 files were saved.  For some unknown reason the net JPG file had the wrong data ant time. Where the PSD had the the correct run date and time.  Cs6, cc 2018 and CC 2019 all saved the jpg files with the wrong date and time. Instead of 2/15/2019  5pm the date was 2/11/2019 10pm on the jpg files.  When I open a template in cc 2019 use replace content and save as jpg manually the jpg is saved with the correct data time.

Any way here is a link Candy-Jars.zip It contain the scripts, jars, labels, and Templates. its 1.5GB I'll leave it up a few days then recover the 1.5GB on my server.

I see no problem in my Save JPG code

function SaveAsJPEG(saveFile, jpegQuality){

var doc = activeDocument;

if (doc.bitsPerChannel != BitsPerChannelType.EIGHT) doc.bitsPerChannel = BitsPerChannelType.EIGHT;

jpgSaveOptions = new JPEGSaveOptions();

jpgSaveOptions.embedColorProfile = true;

jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

jpgSaveOptions.matte = MatteType.NONE;

jpgSaveOptions.quality = jpegQuality;

activeDocument.saveAs(File(saveFile+".jpg"), jpgSaveOptions, true,Extension.LOWERCASE);

}

function SaveAsPSD( inFileName, inEmbedICC ) {

var psdSaveOptions = new PhotoshopSaveOptions();

psdSaveOptions.embedColorProfile = inEmbedICC;

app.activeDocument.saveAs( File( inFileName + ".psd" ), psdSaveOptions );

}

JJMack
JJMack
Community Expert
February 15, 2019

It turned out that jpeg files had the correct file modification date.  File explorer was displaying some other file date.  A file has many dates in its file information. File explorer can display.  Is the script working for you? The only problem I see on my system is that  Photoshop CC 2019 fails occasionally  replacing a smart object layers content.  That is an  Adobe Photoshop CC 2019 bug.  It take my slow 2Ghz machine 1.5hours to populate you 41  labels into your 84 templates.   I'll be removing the Candy-jar.zip from my web server soon. Its 1.5GB.

JJMack
JJMack
Community Expert
February 11, 2019

Today I added a timer to the script to time how long it runs.  I also recorder an Action to create Candy Jar Mockup from your layer group  player it 84 time to create your mockup templates and ran the script.  I walked way and came back some time later.  The script was displaying a Photoshop error it  had caught which pauses the script.   The message was user canceled. Since the script was into processing the mockup templates  at that stage all the the script does is replace Content and save as jpeg.  It was processing the 04LM Mockup template so I let the script continue  and look at the output.  It looks like it is a bug in Photoshop the Replace Content messed up and did  something very strange to the current document. The first 22 Replace content  worked and all the save jpeg worked al 3,444 mockup were save.  However in the 04LM while the first 22 are correct the last 19 are not.  While there is only one shared smart object label that is on both jars the last 19 mockup have different  labels on the jars  which should not be.  So CC 2019  must have so,e weird bug. The net result was there were 3,425 good output files and 19 bad output files. It too 2.7 hours but I doe not know how long the script was pause displaying the  error message.  Here is a Capture of CC 2019 Problem. I may try CS6.

JJMack
Stephen Marsh
Community Expert
January 28, 2019

Sounds like multi-step workflow may be better than trying to do it all in one file.

1) Setup variants in spreadsheet

2) Create variables/data driven graphics in Photoshop, Illustrator or InDesign (data merge).

3) Save out flat labels for each variety and size etc.

4) Batch the placement of the flat labels onto the jar, warping and saving out final files

Bojan Živković11378569
Community Expert
January 28, 2019

Can you post screenshot with example. Please include and Layers panel.

Participating Frequently
January 28, 2019

Here's a screen shot. You can see what the eventual image is supposed to look like (there's also one version with just the small jar, and one with the large jar), so each sweet type has 3 groups, and 4 layer images in total. And you can see the layers panel here.

As an added bonus, you can also see the steps in the action I've created.

I was actually very proud of myself. I was up . til 3am creating an action using really obscure keyboard short cuts that I had to look up, and theoretically it works perfectly. I even found some script that would then run that action as many times as I specified. And based on answers here, I was able to run my Save Groups To JPGs script as part of the action. But it gets as far as running the script, but the script requires me to set a save location in a dialogue box. While recording the macro, I did all this with keyboard shortcuts, but the action isn't picking any of that up. I tried experimenting just keeping to the defaults and pressing okay, but the action won't even click okay for it, I have to go back to my MacBook every 20 minutes to click okay manually.

Is this just a case of the script not being compatible with the action, and it never will be, or is there some secret I'm missing.

I appreciate the advice about Data Driven graphics, but that seems like another level of . learning beyond where I currently am. I can just about get my head around Actions, as I do a lot of work with Macros in Excel. This is almost working, and would work perfectly if it wasn't for that one step in the script.

Participating Frequently
February 9, 2019

I forgot to include that, I added two script to my Photo Collage Toolkit the one I package for you the can replace 1 smart object and one that can replace many I sarted the Scripts with a basic Collage dialog. That include the script for preferences. I'lll post the preferences script.  The Save as steps in the script should be easy for to change you would run for each mockup.  You could save all the output jpeg into a common folder.  Right now the file name are "Label Name Mockup Name"  Where mockup are for each of  you candies. So mockup name = Candy Name.  You could  make the file name "Mockup Name Label Name"  in a common output folder or made a the script create  sub folders for the mockup candy name. MockupName should be Candy Name.

Right now if you save all mockup output files into a common output folder and sort the folder on  file name the lists would be ordered "Label Sweet"  so  so bascly  sorted in Label order.

I tried to make the script a general solution.  You can separate be sweets by creating an output folder for each sweet mockup or have all  output  stored into a common folder  where file name sort will sort in label order. will sort labels together.

The label file name is part of the output file name.  You could save  all output to a common folder and add code into the script to create sub folder for the label name if if did not exist and  add the to  path the output files are saved to. currently the output name is constricted this way

"outputFile = outputFolder + "/" + theNewName +" " + templateName ; // Construct full output file path"

The  var theNewName is your label names the outputFolder the folder you set in the scripts dialog and templateName you seets mockup Name.

So you would check to see if a  folder named  theNewName exist if not create it. then change the output filename to include the theNewName folder to the path something like this:

"outputFile = outputFolder + "/" + theNewName + "/"  + theNewName +" " + templateName ; // Construct full output file path"

For all my Collage scripts. Free Photoshop Photo Collage Toolkit

Here is that missing script Preferences script only some  are referenced in the dialog  for mockups.  The Mockup script onle referebces two of the preferences. 

//* ==========================================================

// 2013  John J. McAssey (JJMack)

// ======================================================= */

// This script is supplied as is. It is provided as freeware.

// The author accepts no liability for any problems arising from its use.

// Image files and Template Alpha Channel "Image 1" should have the same orientation matching Aspect

// ratio is even better.  This script will try to transform the placed Images to match the Image 1 Alpha channel as

// best as it can and even try to handle orientation miss matches.

/* Help Category note tag menu can be used to place script in automate menu

<javascriptresource>

<about>$$$/JavaScripts/PCTpreferences/About=JJMack's Photo Collage Toolkit.^r^rCopyright 2013 Mouseprints.^r^rPreferences</about>

<category>JJMack's Collage Script</category>

</javascriptresource>

*/

// enable double-clicking from Mac Finder or Windows Explorer

#target photoshop // this command only works in Photoshop CS2 and higher

// bring application forward for double-click events

app.bringToFront();

///////////////////////////

//       SET-UP

///////////////////////////

/////////////////////////////////////////////////////////////////////////////////

///////////////////////CUSTOMIZE Here////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////

// Some Hard Coded variables that some day I may put into the dialog options area

var imageStyleList = ['Default Style (None)','Photo Collage Style 1','Photo Collage Style 2','Photo Collage Style 3','Photo Collage Style 4','Photo Collage Style 5','Photo Collage Style 6','Photo Collage Style 7','Photo Collage Style 8','Photo Collage Style 9','Photo Collage Style 10','Photo Collage Style 11'];

var imageStyleDefault = 0; // imageStyleList index number

var textSizeFactor = 4; // > 1 scales down text size

var textFont = "ArialMT"; // Photoshop internal font name

var textAngle = -10; // center text angle

var textColor = new SolidColor; // text color

    textColor.rgb.red = 255;

    textColor.rgb.green = 255;

    textColor.rgb.blue = 255;

var textStyleList = ['Default Style (None)','Shiny Metal','Shiney Metal No Stroke','Strong Metal','Strong Metal No Stroke','Clear Emboss - Inner Bevel','Clear Emboss - Outer Bevel','JJMack Overlay'];

var textStyleDefault = 0;                       // textStyleList index number

var textLocationDefault = 7;                    // text Location Default Bottom Center

var templateFolder = "C:/Program Files/Adobe/Adobe Photoshop Templates/";

//var templateFolder = "E:/Public Files/Pictures/Adobe Photoshop Templates/";

//var imagePath = "~/My Documents/My Pictures/"; // Windows XP

var imagePath = "~/Pictures/"; // Windows 7

//var imagePath = "E:/My Files/Pictures/";

// End hard coded variables

/////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////


Nearly there then. I think I can work all that out. I doubt I can write the code to create folders automatically, but if everything is just ordered by label name, then I'll be able to find them in big chunks in the folder, and it won't be a big job to grab them and drag them into their appropriate folders.

But before I can play with that, I've tried to test the code as is, and produce the images that you have. It will run now, and doesn't get stuck at that line, but I'm still having a couple of issues:

1) when the dialogue box pops up, the first two buttons ('Select' and 'Browse') won't work, so I can't select the files I need. The second 'Browse' button does work though. I am able to just copy and paste the file paths from Finder though, so it's not a big problem.

2) If you can see in the screenprints below, something hasn't gone quite right. It's ended up saving the warped labels, but not with the sweets.

3) Will I have to run this script individually for each mockup I make. The dialogue box asks me to select a mock up file, rather than a folder, but there's going to be 84 of these (and another 15 varieties that I've got to add next week, so 45 more images), so that's still going to end up being a massive job. Would it be possible to select a folder with all the mockup PSDs in, then it runs them through one at a time?

Brainiac
January 28, 2019

Look up data-driven graphics. You would save the labels out at separate files, create a spreadsheet that specifies which label graphic goes with what, and create a master image that has the data set imported. If I had to do this every month, that would be my first idea.

JJMack
Community Expert
January 28, 2019

Be aware the Data driven graphics does not support replacing Smart Object layer objects.  Your Template can contain Smart Object layers  as part of its design. However Data Driven graphics support replacing raster image layers and text layers. 

Script and actions can include other scripts and actions in their processing. Script can use other Scripts.  Action can play actions a record menu file>scripts>script names steps.  Script's can include other script and use function in the included script. Script cam plat action using Doaction statements.

JJMack