8 Replies Latest reply on Mar 16, 2016 11:22 AM by Silly-V

    Passing 'constant' to .jsx script via action

    StampyTheElephant

      I have a script that opens one of a number of template files so the contents can be pasted into one of many files. I'm batching these files with actions (one for each template), but I'd like to be able to pass the specific template required to the script without requiring user input.

       

      This might require some clarification.

       

      Say I have three folders of images, 'red', 'blue' and 'green', each containing 1000 images.

       

      I want to run the 'red' actions on all the images in 'red', the 'blue' actions on all the images in 'blue', and the 'green' actions on all the images in 'green'. In all the actions, I want to open up the respective template, so in 'red' I want to open the 'red' template, in 'blue' the 'blue' one etc. I appreciate in this simple example, I could just write three scripts with the paths hardcoded, but I actually have twelve actions currently, and the potential for this to grow.

       

      My original idea was for the relevant action to enter some text, eg a textbox with the word 'red', which can then be picked up within the script as a variable, but unfortunately the actions won't allow text entry.

      I've looked into variables, but I don't see how I can make that applicable here.

      I've also looked at using pre-generated text strings as symbols, but I've had real trouble getting the action to choose the correct string.

       

      I also wondered about having another document open in the background containing the textbox I need, but I can't get the action to select an object from a different document.

       

      Using the clipboard is impractical because it's used for other things within the action.

       

      Is there a solution to this, or am I resigned to writing multiple scripts? For infor I'm currently using CS5.

        • 1. Re: Passing 'constant' to .jsx script via action
          CarlosCanto Adobe Community Professional & MVP

          if I understood correctly, your problem could be solved if you could have a text frame with the word "red", then when you run your action and your action run your script, the script would pick up the word "red" and do its thing, is that right?

           

          if so, create your text frames, name them "red", "blue", "green", open the Attributes Panel, and give them Notes matching their respective names, then in your Actions you can select any of them by inserting a "Select Object...", this command will select an object whose Note matches the text of your choice.

           

          that way your script can read the contents of the currently selected item and do its thing accordingly.

          • 2. Re: Passing 'constant' to .jsx script via action
            StampyTheElephant Level 1

            I think I tried something like this too, but it's very possible I missed something.

             

            Please correct me if I'm wrong, but I think the text boxes would have to be in another document. They don't already exist in the file I'm currently batching, and I can't add text via an action.

             

            When I tried this, I don't believe it let me select an onject from within a different document. I really hope you can point me at something I overlooked because this sounds perfect.

             

            I realise I didn't make it clear previously - the original images are all in .tif format. They're opened within Illustrator and a number of different processes are applied to them (depending on which action set is used), and then a template of paths is overlaid - which template is also determined by the action set.

            • 3. Re: Passing 'constant' to .jsx script via action
              Silly-V Adobe Community Professional

              StampyTheElephant wrote:

              the actions won't allow text entry.

              You can pass a custom string into an action via the Attributes > Notes feature, but you can also create a new layer with a custom name, which can also be used as a marker. To expand on Carlos' advice, it is possible to not even have the 'noted' art items in the document to begin with, as you can add temporary art items and assign to them custom notes to be read by a following script, and then these temporary items can be erased afterwards as well.

              • 4. Re: Passing 'constant' to .jsx script via action
                StampyTheElephant Level 1

                Ah, now there's an idea, thanks. Let me go away and see what I can do with that! Not sure how to retrieve the contents of the attribute notes in a script, but I've got a direction to look in, ta.

                • 5. Re: Passing 'constant' to .jsx script via action
                  Silly-V Adobe Community Professional
                  Not sure how to retrieve the contents of the attribute notes in a script

                   

                  alert(pageItem.note);

                  • 6. Re: Passing 'constant' to .jsx script via action
                    StampyTheElephant Level 1

                    Haha! Thanks.

                     

                    I tweaked it a little, but the gist of what I'm using currently is:

                     

                    var doc1 = app.activeDocument;

                    for (i = 0; i < doc1.pageItems.length; i++) {

                         note=doc1.pageItems[i].note;

                         if (note.length > 0) {

                              x=note;

                              doc1.pageItems[i].remove();

                         }

                    }

                    alert(x);

                     

                    It won't work correctly if there are multiple notes, but in my case there won't be. Thanks for all your help, Silly-V and CarlosCanto.

                     

                    I hope you don't mind that Silly-Vs posts sent me off in the right direction so I'm going to choose that as the answer.

                    • 7. Re: Passing 'constant' to .jsx script via action
                      CarlosCanto Adobe Community Professional & MVP

                      How dare you marking his answer as the correct one, that's unacceptable!! Just kidding

                      • 8. Re: Passing 'constant' to .jsx script via action
                        Silly-V Adobe Community Professional

                        If you choose to have your action create the temp object and assign the note, your document state will be in such a position that your selection will be limited to the one temp art item. Then you will not need to go through each item in the document, but can rather use document.selection[0].note, and could use a simple "clear" command, if situation allows, to clear out the temp item immediately after the script is done