6 Replies Latest reply on Jun 6, 2018 6:10 AM by Lou_Chou

    Change same text across multiple PSD files?

    Lou_Chou

      Hi,

       

      I've searched for a solution like this around the forums, and while a lot of variations exist on this idea, I've not found one that does exactly this as yet, perhaps you could help?

       

      So, I've got a handful of PSD files, let's say they're called

      - poster.psd

      - cover.psd

      - advert.psd

       

      In each of these files exists the same text, let's say it's social media info, for this example we'll say

      - twitterusername

      - instagramusername

       

      Is there a way, via one script, to change the social media info across those 3 PSD files, without me running the script one each PSD, one at a time? Perhaps if I simply have them all open, it checks them each and replaces text?

       

      Many thanks in advance. If anyone can provide a solution it'd be a huge time saver, and I'd be more than willing to pay/donate some money for the effort.

       

      Edit: Sorry, I'm using Adobe Photoshop CC v19.4.1

        • 1. Re: Change same text across multiple PSD files?
          sidpalas Level 2

          You can open the files from within the script and there are multiple ways to specify the files:

           

          1) If it is always the same files, you could hard code the paths to each into the script (this is the easiest, but not very flexible)

          2) You could have the script call app.openDialog() which will bring up a file selection window where the user can select all of the relevant files

           

          How you go about finding and replacing the text will differ based on how you have structured the .psd files (for example, is the text in its own layer?). Also if you make the structure and naming conventions (for layer names, etc...) the same across the documents it will make scripting the solution much easier.

           

          If you posted an example or two of your files, I can help.

          • 2. Re: Change same text across multiple PSD files?
            sidpalas Level 2

            I created the minimal example below:

            Screen Shot 2018-06-05 at 12.03.49 PM.png

            and wrote the following script which (I think) accomplishes your goal:

             

            #target photoshop
            var files = app.openDialog ("Please select the relevant files");
            var newTwitter = prompt("Type the new Twitter handle:");
            var newInstagram = prompt("Type the new Instagram handle:");
            for (var i = 0; i < files.length; i++){
                var file = new File(files[i]);
                var docRef = app.open(file); 
                var twitterLayer = docRef.artLayers.getByName("twitterHandle");
                twitterLayer.textItem.contents = newTwitter;      
                var instagramLayer = docRef.artLayers.getByName("instagramHandle");
                instagramLayer.textItem.contents = newInstagram;
                docRef.close(SaveOptions.SAVECHANGES)
                }
            

             

            Let me know if this makes sense of if you have additional questions!

            1 person found this helpful
            • 3. Re: Change same text across multiple PSD files?
              Lou_Chou Level 1

              Wow, that's awesome! I've been using Photoshop for half my life and didn't even know you could do this kinda thing.

               

              Can I pay you for your time on this?

              • 4. Re: Change same text across multiple PSD files?
                Lou_Chou Level 1

                In fact, sorry, just one thing I'm realising - is it possible to target text inside a group, as well as outside? This would really be quite useful. Let's call the groups "twitterWrapper" and "instagramWrapper" for consistencies sake.

                • 5. Re: Change same text across multiple PSD files?
                  sidpalas Level 2

                  Do you mean the text layers containing the usernames are in layer groups like this?

                  Screen Shot 2018-06-05 at 7.41.02 PM.png

                  To handle this you will first need to use the layerSets object before getting the specific layers. See below:

                   

                  #target photoshop
                  
                  var files = app.openDialog ("Please select the relevant files");
                  
                  var newTwitter = prompt("Type the new Twitter handle:");
                  var newInstagram = prompt("Type the new Instagram handle:");
                  
                  for (var i = 0; i < files.length; i++){
                      var file = new File(files[i]);
                      var docRef = app.open(file);
                     
                      var twitterGroup = docRef.layerSets.getByName("twitterWrapper");
                      var twitterLayer = twitterGroup.artLayers.getByName("twitterHandle");
                      twitterLayer.textItem.contents = newTwitter;   
                     
                      var instagramGroup = docRef.layerSets.getByName("instagramWrapper");
                      var instagramLayer = instagramGroup.artLayers.getByName("instagramHandle");
                      instagramLayer.textItem.contents = newInstagram;
                  
                      docRef.close(SaveOptions.SAVECHANGES)
                      }
                  

                   

                  No need to pay me. Pay it forward somehow

                  1 person found this helpful
                  • 6. Re: Change same text across multiple PSD files?
                    Lou_Chou Level 1

                    Wow, truly fantastic help. You've saved my workflow a lot of time, thank you!