26 Replies Latest reply on Mar 26, 2009 8:23 AM by tynan
      • 1. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
        tynan Level 1
        hi, raw newbie on applescript but I'm trying to set an applescript that will search for various text attributes and apply various existing character styles in Indesign CS3

        So far so good except the text override(s) remain in place, if I apply the same character style in Indesign the overrides are cleared

        Is there some sort of option etc that I can add to my script that will clear any overides as the character style is applied?

        script code below, thank-you
        .....

        tell application "Adobe InDesign CS3"
        activate
        tell parent story of item 1 of selection

        --find/change text preferences
        tell application "Adobe InDesign CS3"

        --Search for the string "Text"
        set properties of find text preferences to {font style:"Italic"}
        set properties of change text preferences to {applied character style:"Italic CH"}

        --FIND/CHANGE OPTIONS
        set case sensitive of find change text options to false
        set include footnotes of find change text options to true
        set include hidden layers of find change text options to false
        set include locked layers for find of find change text options to false
        set include locked stories for find of find change text options to false
        set whole word of find change text options to false

        set properties of find text preferences to {font style:nothing}
        set properties of change text preferences to {font style:nothing}


        --DO IT
        try
        tell parent story of item 1 of selection to change text
        end try
        end tell
        end tell
        end tell
        • 2. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
          sstanleyau Level 4
          You can use the "apply character style" command. So you'd do a find instead<br />of find-change, then loop through the results using the command.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Sessions <a href=http://scriptingmatters.com/aspro>
          • 3. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
            tynan Level 1
            Hi Shane and thanks for that

            I seemed to have overcome the original problem, I've certainly got it working for the basic font styles like bold, itlaic and so on

            What's driving me mad now is finding Underlined text

            And small caps

            The literature seem a bit thin on finding attributes like that

            I've a huge amount of Word text in hundreds of documents to search and replace, I have all the searches set within Indesign but life's too short to running them over and over again

            Really need to be able to fine Underlined Italics, Underlined bold, Underlined Bold Italic text

            And then the same all over again but in smallcaps

            is it possible, I read some dark posts from Ole at Adobe about finding underlined text plus a style

            seems hard to belive that it can't be done when it's so easy in the Find/Replace dialogue within Indesign

            ID CS3 on Mac OSX if it matters

            Any help realy appreciated

            Thanks
            Tynan
            • 4. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
              sstanleyau Level 4
              Have a look at the sample script called FindChangebyList or something<br />equally asHardToRead.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Sessions <a href=http://scriptingmatters.com/aspro>
              • 5. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                tynan Level 1
                I have and it is

                I've got it running the simple 'find italics' and 'apply yadya yada character style'

                And I can see how the GREP will work

                What's uterly blocking me is how to find Underlined text with various additional font styles, It'd be valuabe even to know that it can't be done

                The potential is clearly so huge but I get the feeling that it's rather limited and very badly documented other than the basic finds

                thanks
                Tynan
                • 6. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                  sstanleyau Level 4
                  On 25/3/09 6:32 PM, "Tynan" <member@adobeforums.com> wrote:<br /><br />> What's uterly blocking me is how to find Underlined text with various<br />> additional font styles<br /><br />Look them up in the dictionary. So you'll have something like:<br /><br /><br />grep    {find what:"  +", underline:true, font style:"Bold}<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Sessions <a href=http://scriptingmatters.com/aspro>
                  • 7. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                    [Jongware] Most Valuable Participant
                    If you're not stuck with using AppleScript, you could use my preptext JavaScript. (If you are, you might translate it.)

                    See this announcement.

                    > What's uterly blocking me is how to find Underlined text with various additional font styles...

                    It does that, and more: if an additional style combination is needed, the script creates it.
                    • 8. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                      tynan Level 1
                      Thanks gents

                      I did diddle with the textprep one, my javascript is as good as my applescript ...

                      It's going to have to generate the exact names of the character styles that we have already have as the Word files are from all over the place and will have variations in the Word formatting, I did start on it but wasn't sure that it'd take me all the way, clever though, no doubt and it's in reserve

                      GREP, that looks spot on thanks Shane, I didn't think GREP would find text attributes, that 'underline:true' is exactly what I was trying as a text search, it runs without error but didn't find anything

                      I'll try it as a grep search shortly

                      Thanks again, expert advice is always appreciated

                      Tynan
                      • 9. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                        tynan Level 1
                        grep {find what:" +", underline:true} {applied Character Style:"Body text (Underscored)"}

                        tried that, no errors but no finding either, tried some variations, no errors but no find

                        there's a hideous lack of anything in google about this

                        stumped ...

                        is the 'dictionary' the underline option routinely say it's for setting things to underline, is that just sloppy commenting or is that implying that it's always to turn underline on rather than find it
                        • 10. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                          tynan Level 1
                          early days but textprep is looking promising

                          it's picking up all the underlines with the bold, italics and bold italics and marking them with the pre existing character styles

                          ditto the regular bolds etc

                          smallcaps and allcaps to go

                          ...
                          • 11. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                            [Jongware] Most Valuable Participant
                            >smallcaps and allcaps to go..

                            Do you need all styles to pre-exist? I thought you mentioned earlier you had to create all possible combinations by hand. The script does that for you!

                            If you want, you can create a few of the basic styles beforehand, such as "Bold" and "Italic". The script should be smart enough not to re-create them. However, newly created styles are not automatically "based on" a basic style.

                            If you need those styles by another name you will have to rename them in the script, but you cannot choose names for combinations, i.e., if you rename "Bold" to "something else", it will be combined as "something else+Italic".
                            • 12. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                              tynan Level 1
                              my ham fisted modding seems to have worked, I fiddled a bit with your code and hard coded some names in in place of your dynamic ones

                              it was working perfectly for the underlined variations and the basic variations

                              it went wrong when i got to small caps, my very poor javascript knowledge I suspect

                              does that make sense?

                              where the character style name I tell it to allocate to various styles matches the character styles pre existing, it works and applies the pre existing character style

                              so where it finds some 'bold' that text gets my 'Body Text Bold' character style applied to it

                              and so on

                              I need to find text attributes for, and apply pre existing character styles to
                              bold, italics, bolditalic
                              underlined, underlined bold, etc
                              small caps
                              all caps
                              smallcaps underlined, small caps underlined bold, etc

                              I think it's going to work out ok if I can stop buggering up your code ...
                              • 13. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                                tynan Level 1
                                woohoo!

                                working!, thanks a stack for the textprep code, once the block at the top captures the variables and does whatever else it does, the rest is simple enough

                                I've posted my changes for anyone else that's in the same boat, apologies for any ghastly coding in there, but it works!

                                thanks again, this code appears at L102 and runs all the way down to the 'try'

                                ............
                                if (StyleName == "")
                                {
                                // bolds etc
                                if (bold)
                                StyleName = "Body text (Bold)";
                                if (italic)
                                {
                                if (bold)
                                StyleName = "Bold text (Bold/Italic)";
                                else
                                StyleName = "Body text (Italic)";
                                }

                                // allcaps and smallcaps to allcaps, despite the character style name!
                                if (allcaps)
                                {
                                StyleName = "Small caps (Body text)";
                                if (italic) StyleName = "Small caps (Italic)";
                                if (bold) StyleName = "Small caps (Bold)";
                                if (bold)
                                {if (italic) StyleName = "Small caps (Bold/Italic)";
                                }
                                } else
                                {
                                if (smallcaps)
                                {
                                StyleName = "Small caps (Body text)";
                                if (italic) StyleName = "Small caps (Italic)";
                                if (bold) StyleName = "Small caps (Bold)";
                                if (bold)
                                {if (italic) StyleName = "Small caps (Bold/Italic)";
                                }
                                }
                                }

                                // underlined
                                if (underline)
                                {
                                StyleName = "Body text (Underscored)";
                                if (italic) StyleName = "Body text (Underscored) italic";
                                if (bold) StyleName = "Body text (Underscored) bold";
                                if (bold)
                                {if (italic) StyleName = "Body text (Underscored) bolditalic";
                                }
                                if (smallcaps)
                                {
                                StyleName = "Body text Smallcaps (Underscored)";
                                if (italic) StyleName = "Body text Smallcaps italic (Underscored)";
                                if (bold) StyleName = "Body text Smallcaps bold (Underscored)";
                                if (bold)
                                {if (italic) StyleName = "Body text Smallcaps bolditalic (Underscored)";
                                }
                                }
                                if (allcaps)
                                {
                                StyleName = "Body text Smallcaps (Underscored)";
                                if (italic) StyleName = "Body text Smallcaps italic (Underscored)";
                                if (bold) StyleName = "Body text Smallcaps bold (Underscored)";
                                if (bold)
                                {if (italic) StyleName = "Body text Smallcaps bolditalic (Underscored)";
                                }
                                }
                                }
                                • 14. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                                  [Jongware] Most Valuable Participant
                                  Your all caps styles are named the same as the small caps ones :-)

                                  But I can see how this is an improvement over my blind "a+b+c" stuff. Ghastly or not, it does the job. Not bad for a first project, Tynan!
                                  • 15. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                                    tynan Level 1
                                    Yep, the older books are either using smallcaps or allcaps, the new ones will be allcaps

                                    your blind approach is excellent when the incoming styles are unknown, and it lends itself very well to being hotwired to use preset styles

                                    All the good stuff that I couldn't have managed was yours, I know some php and sundry scripting so I could bodge the rest

                                    thanks again for your original script, on the shoulders of giants and all that, but yes, I'm bloody pleased with this

                                    cheers fella!

                                    Tynan
                                    • 16. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                                      tynan Level 1
                                      ah

                                      one more question

                                      I have another search to do, for single characters in a fancy font that does dingbat like symbols

                                      can your fancy FindAttr function also capture the font as opposed to the style?

                                      or any idea on how to tackle that?

                                      Thanks again
                                      Tynan
                                      • 17. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                                        [Jongware] Most Valuable Participant
                                        Well, I *think* it can, but I'm guessing it would be overkill to build it into the main huge loop construction. To do that, you would use something like<br /><br /><pre>var fontlist = ["Trebuchet MS", "Haettenschweiler" ]; // whatever ...<br /><br />for (fonts=0; fonts<fontlist.length; fonts++)<br /><br />   app.findTextPreferences.appliedFont = fontlist[fonts];</pre><br />with a suitable char style name in the replace.<br /><br />It would be overkill because -- most likely -- you're not interested in bold or italic dingbats (are you?).<br /><br />It might be better to write a separate find/change loop for this -- just the above lines, and outside the fancy looping.<br /><br />I hope you are just aiming to replace a hardcoded font by the same in a char style. If you intend to replace the<br />i font<br />as well, you'll probably need to replace individual characters with others too, and in that case I'd advise just using the FindChange script and its associated configuration text file.
                                        • 18. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                                          tynan Level 1
                                          it's already in the right font, I just need to apply the character sheet for it, so find 'whatever' font and apply 'whatever' character style.

                                          I'd be using it on lots of no more than 5 page docs so it's running in a few seconds at present, as regards overkill

                                          two different fonts so two search and replaces

                                          is that code a runner? sorry it's all a bit greek to me at the moment

                                          I'm happy using the findchange script only I can't work out what to use for the Find bit to find a font instance.

                                          thanks once again
                                          Tynan
                                          • 19. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                                            tynan Level 1
                                            I think I get it ...

                                            I can hard code the 'app' line for the two fonts I need to do?

                                            so

                                            app.findTextPreferences.appliedFont = FONT1;

                                            is the find part that will find instances of the font?

                                            go on save me an hour of my life and post the whole line

                                            please

                                            thanks
                                            Tynan
                                            • 20. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                                              [Jongware] Most Valuable Participant
                                              Yes, it is that simple. To find a particular font "Dingbats", just supply the name:

                                              >app.findTextPreferences.appliedFont = "Dingbats";

                                              If you need to discern different styles of a same font, append the style name after the font name, with a tab inbetween:

                                              >app.findTextPreferences.appliedFont = "Dingbats\tRoman";

                                              and

                                              >app.findTextPreferences.appliedFont = "Dingbats\tItalic"; // (ugh!)

                                              (the "\t" is a tab character in a JavaScript string).

                                              Be sure to reset findTextPreferences to zero
                                              i just before
                                              these lines, to avoid contaminating the "find" dialog with previously set parameters. That's what the lines

                                              app.findTextPreferences = NothingEnum.nothing;
                                              

                                              app.changeTextPreferences = NothingEnum.nothing;
                                              do at the start of each of my change loops -- they reset the Find dialog to entirely empty.
                                              • 21. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                                                [Jongware] Most Valuable Participant
                                                (logically, resetting the entire dialog is not necessary if you just searched for one font only, and then next for just another font. but it's better be sure.)
                                                • 22. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                                                  tynan Level 1
                                                  goody, thank-you

                                                  will report back tomorrow, hopefully happy!

                                                  you're a very nice man

                                                  night
                                                  Tynan
                                                  • 23. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                                                    tynan Level 1
                                                    right

                                                    this is the new bit I've cobbled together from guesswork and hop

                                                    //Apamapref
                                                    app.findTextPreferences = NothingEnum.nothing;
                                                    app.changeTextPreferences = NothingEnum.nothing;
                                                    app.findTextPreferences.appliedCharacterStyle = app.activeDocument.characterStyles[0]; // [None]

                                                    app.findTextPreferences.appliedFont = "Apamapref";
                                                    app.changeTextPreferences.appliedCharacterStyle = "Apamapref";

                                                    If I stick that inside the loop, it runs ok, it fins all the instances of Apamapref but then removes them, poof gone. If I stick at the very end of the existing code nothing happens

                                                    clueless as to what goes on at the mo

                                                    outside i best I think? but I'm guessing that there's some sort of 'try' type line to actually act upon the preferences?
                                                    • 24. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                                                      tynan Level 1
                                                      I got it working in the javascript findchangebylist using this line

                                                      text {appliedFont:"Apamapref"}{appliedCharacterStyle:"Apamapref"} in the support txt file

                                                      I copied and pasted the whole bloody findchangeby list script in before the textprep code and now it does the Apamapref font, which is nice although I suspect it's a rather bloated way of doing it

                                                      happy for the moment although if the missing line (assumed) to make the code tweak work in the original textprep script can be suggested, that's be good
                                                      • 25. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                                                        [Jongware] Most Valuable Participant
                                                        I'd have to review your entire script line by line. It *might* just be some side effect of an earlier command.

                                                        Fortunately, JS is blisteringly fast for CS3 (not so in CS and CS2 :-(), so I doubt you'll see any serious side effects from inserting the entire script. The main preptext routine is much slower.
                                                        • 26. Re: Clear text overrides in applescriot for Indesign CS3 on Mac OSX 10.5.6
                                                          tynan Level 1
                                                          it's cool, as it happens, splicing in the findchangelist script opens up the easy addition of the find/changes in there so it works for me

                                                          I think I'm good, thanks once again for your original script and your help since then, saved me a lot of time and made me look clever, which is always nice

                                                          laters
                                                          Tynan