7 Replies Latest reply on Sep 11, 2008 9:28 AM by GagnonEric

    Using BRACES in AppleScript to assign para style

      Here's my problem (most likely very basic, I'm sure):

      I'm trying to replace all occurrences of tags like {BL} with a paragraph style BL. I have been trying to do this with the FindChangeList.txt file and syntax:

      text {find what:"{BL}"} {applied paragraph style:"BL"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Find all BL tags and replace with BL para style.

      The script changes other elements in the FindChangeList.txt file (double spaces, -- to em dash, etc.) but not the paragraph style. Ideally I'd also like the script to delete the {BL} tag from the text as well.

      Really frustrating!
        • 1. Re: Using BRACES in AppleScript to assign para style
          Level 1
          When you say "tags" do you mean XML tags, or just some text with the style applied? If you want to change a para style "{BL}" with para style "BL" then you don't want to search for specific text. I believe you can do a F/C on just the para style, you can do that by hand at least. Changing a text with XML tag to a para style may be a little more involved (but I've not done that before).
          If you can explain your problem a bit more precisely that would help.

          • 2. Re: Using BRACES in AppleScript to assign para style
            Level 1
            Sorry for the lack of info. Maybe this will help.

            When I get a Word doc from a copyeditor, they have inserted actual text like {BL} or {NL}. These correlate to an InDesign paragraph style BL or NL. The actual Word file that has been flowed into the InDesign template comes in as straight text (no Word styles attached).

            I'm trying to search for all text instances of {BL}, assign the InDesign para style BL, then delete the text instance of {BL}.

            I'm wondering if I'm having trouble because AppleScript uses the braces { } as command markers. Unfortunately I'm stuck with braces from the copyeditor. I have no trouble doing a search and replace manually from within InDesign, but would really love to automate the process with a script. I typically have 25+ different "tags" that I search and replace by hand. It seemed to me that the FindChangeList.txt script would be the perfect place to start. When I run it, the sample changes (delete double spaces, double dash to em-dash, etc.) all work, but I can't seem to get any of my additions to run.

            Thanks in advance for any help you can give.

            • 3. Re: Using BRACES in AppleScript to assign para style
              GagnonEric Level 1

              1) Check the encoding of your file (utf-8, not MacRoman!)

              2) Have a look at http://osaxen.com/files/textcommands1.1.3.html wich let create unicode string (character) using key code in case #1 is not enough.

              • 4. Re: Using BRACES in AppleScript to assign para style
                Level 1
                Hi Scott,
                Don't have enough time to write a script sample now. But I believe that you can make the find string search for a bracket, that *should* be no problem. Maybe you need to declare set myLBracket to "{" and call myLBracket in the Find Change part of script, instead of doing it directly. Or maybe you just need a quote around it? You'll want to replace it with nothing then, correct?
                But then after you remove the {BL}, or actually before, you want to assign some paragraph style "BL" to the string of text, between {BL} and some other tag or another {BL}. (Sorry I don't work with Word to know how it's doing its formatting thing.) That might require getting the offset of the first {BL} in your text, then getting the offset of the second, then applying the inDesign BL style from the first to the second offset (of characters). THEN you can delete your text {BL}, or at least the first two. Then repeat the process, find offsets, apply style, delete {BL}.
                • 5. Re: Using BRACES in AppleScript to assign para style
                  GagnonEric Level 1
                  SuperMacGuy gave a better explanation..

                  I did a test with the base script of replace in CS3 and it does work, but i doesnt have any handling of open and closing tags.

                  You would need more a function like this:

                  CloseTag could be optional if you always have the same code to close the tag, like in xml ({tag} and {/tag} by exemple)

                  If you only have startTag, there will maybe more work to do, say you will have to evaluate if the styling has to be applied until:
                  -- End of paragraph.
                  -- Next tag (different?)
                  -- End of text.

                  If you are using startTag and closeTag having the same name, you will have check if the pairs are complete! :)

                  If you want better help, feel free to post a text sample!
                  • 6. Re: Using BRACES in AppleScript to assign para style
                    Level 1
                    First of all--thanks for your time and effort on this. Here's an example of text I flow into InDesign from the Word doc:

                    {T1}My first meeting was not with teachers, but with administrators, and occurred in January during their first year of implementation. The three school principals as well as the Curriculum Director brought a list of concerns for me to address, based on what they were hearing from their teachers and parents. The following is a list of concerns they compiled:
                    {BL}Parents have questions and concerns
                    {BL}How are skills, such as operations with fractions, addressed and practiced?
                    {BL}What about increased reading demands on struggling readers?
                    {BL}How can we move more quickly through the lessons, yet still address the concepts and skills in a thorough manner?
                    {BL}How do teachers find the time to prepare the materials and then plan for this type of lesson?
                    {BL}Where can teachers include their own special interests and projects?{/BL}
                    {T1}District administrators pledged to continue to support the teachers in all ways possible. They also agreed to give release time during the school day for in-service and to provide substitute teachers as needed.

                    The first para needs a T1 paragraph style from InDesign
                    The next 5 graphs get a BL para style from InDesign (ideally the first would get BL1 and the last would get a BLX--these add space above and below the bullet list. This is probably scriptable, but at this point it's wishful thinking!)
                    The next graph gets a T1 style from InDesign.

                    Any ideas?

                    • 7. Re: Using BRACES in AppleScript to assign para style
                      GagnonEric Level 1
                      How much file to you have to process? Is this representative of all the case you will have to handle? It looks to me that the data format is not consistent, it's possible to handle it, but it will just make the processing more difficult (at least, it doesnt look like you are having tags/state nesting).<br /><br />Aussmed the data would be corrected (open and close tag), what you are trying to do could also be done using a xml approach:<br /><br />By exemple, if you would have:<br />{T1}ghjghj{/T1}<br />{BL}gjgjhgj{/BL}<br />{BL}ghjghjghj{/BL}<br />{BL}ghjghjghj{/BL}<br />{T1}tyrtyrty{/T1}<br /><br />Then i would be trivial to convert it to xml using text processing (in applescript or any other general language)(concatenation + seachReplace) to :<br />...<br />  <PageItem><br />    <T1>ghjghj</T1><br />    <BL>gjgjhgj</BL><br />    <BL>ghjghjghj</BL><br />    <BL>ghjghjghj</BL><br />    <T1>tyrtyrty</T1><br />  </PageItem><br />...<br /><br />Or even like this one to regroup the BL items:<br />...<br />  <PageItem><br />    <T1>ghjghj</T1><br />    <LIST><br />     <BL>gjgjhgj</BL><br />     <BL>ghjghjghj</BL><br />     <BL>ghjghjghj</BL><br />    </LIST><br />    <T1>tyrtyrty</T1><br />  </PageItem><br />...<br /><br />Then:<br /> 1) Import that document in Indesign.<br /> 2) Tag a page item with PageItem node.<br /> 3) Use Map Style to Tag to apply the style.<br /><br />Converting the first BL and Last BL, could be as simple as opening the XML and changing the name of the first child and last child of <LIST> by exemple. This could be done with XSLT/ XPath during the processing or inside Indesign as a post-process (before style apply) with a script (using the xml api)).<br /><br />I personnaly like very much this approach (pre-generated XML) because alot can be done manually (to test or to handle problematic documents) and alot of processing can be done using other tools than Applescript/Javascript (in my current project, i was handling word to xml conversion using Realbasic).