5 Replies Latest reply on Jul 22, 2014 3:01 AM by Muppet Mark

    Changing text with Applescript changes font attributes

    moviesign37

      I've been working up a multistep Applescript (which I'm learning as I go) to change up a bunch of files in Photoshop CC. The last part involves changing the contents of an existing text layer (with paragraph text box set for proper placement/size) in the template file, which it does, but it doesn't honor the attributes of the text layer. Size, leading, and baseline all shrink considerably. If I drag-select the text manually and change it manually, it works as expected: just the text changes. Automated, the text changes, but the size goes from 18pt to 4.29pt. I've been searching and experimenting for hours and can't figure out where this change is coming from. Right now, I'm doing an end run around it by cheating the attributes back with an Action, but I can't believe that's the right way.

       

      Here's the line of code I'm using to make the text change:

      set contents of text object of art layer 1 of current document to "Hello" ("hello" will be replaced by contents from a variable; just using it here for testing)

       

      Can anyone explain why this is happening/what I'm doing wrong? The scripting reference hasn't helped much. Thanks in advance!

        • 1. Re: Changing text with Applescript changes font attributes
          Muppet Mark Level 5

          Text in PS is very hard to work with from the scripting POV.

          When you replace text layer contents PS will apply attributes of the first character to all...

           

          Sent from my iPhone

          • 2. Re: Changing text with Applescript changes font attributes
            moviesign37 Level 1

            Thanks for the response, Muppet. I've just abandoned the whole thing since sometimes things worked and sometimes they didn't (even "deselect" was a crapshoot, depending, apparently, on the image). Not sure if Applescript was the problem or Photoshop. My Illustrator tests with Applescript have all been pretty successful, and I guess I got cocky. Time to buy a JavaScript reference, I suppose...

            • 3. Re: Changing text with Applescript changes font attributes
              Muppet Mark Level 5

              What are you trying to do…? No need to but Javascript Ref you will find loads FOC. NOT all will apply as ExtendScript is based on an old version.

              You will need to learn the base classes as the guides don't help with any of that. They expect that you learned the basics elsewhere.

              Scripting language won't change an app's behaviour changing text will do the same in given both…

              Some actionmanager code may let you dig deeper but everything I've seen is a minefield with editing type…

              • 4. Re: Changing text with Applescript changes font attributes
                moviesign37 Level 1

                I was trying to process a pile of images to open, move a layer into a new template, resize it, change one of two text layers based on the filename of the source image, then save the template as that name with a "CSTM" suffix to a different folder.

                 

                Even though I got everything to work (usually), I was still running into random issues as it was trying to process all the files in the folder. Likely something I was doing wrong, but roughly three images would work fine, then the fourth would hang on a line of code that had worked flawlessly on the other three (all images were based off the same template so seems like they should have all worked). Repeated attempts on a single file would work  sometimes, sometimes not, before it even got to the type. It was baffling. So I just did them by hand. Took less time than fighting with the script for another day.

                 

                I didn't think swapping over to JavaScript would make things necessarily magically start to work, just figured JS support would be more robust/consistent than AS.

                • 5. Re: Changing text with Applescript changes font attributes
                  Muppet Mark Level 5

                  Yes you certainly will find more help here if using JS over AS and yes cutting another's tech does reduce problems…

                  Thats my experience… I've had less problems particulally app versioning with JS.