15 Replies Latest reply on Jun 26, 2014 9:27 AM by nellbern

    deleting unused paragraph styles and swatches  ID CS2

      Hi, I posted this on Macscripter's great AS forum, but unfortunately haven't had a solution, The problem is that the script deletes all unused paragraph styles as it should, but it also deletes styles upon which others are based, therefore trashing the document. If I have a body text style, then make a new style based on it, if body text isn't used, it gets deleted and the new style gets set to the default (losing formatting, etc). Oddly, when I delete unused styles from the paragraph styles palette ID seems to be able to 'factor in' this 'based on' issue. Anyway, here's my script:

      tell application "Finder"
      set file_list to selection

      repeat with process_item in file_list
      set the_alias to alias ((file_list as string) & (process_item))
      tell application "Adobe InDesign CS2"
      activate
      open the_alias
      set theDoc to active document
      tell theDoc
      set myParagraphStyles to every paragraph style of theDoc
      set theCount to count of myParagraphStyles
      repeat with n from (count myParagraphStyles) to 2 by -1
      set myCurrentStyle to item n of myParagraphStyles
      my RemoveUnusedStyle(myCurrentStyle)
      end repeat
      end tell
      end tell
      end repeat
      end tell
      on RemoveUnusedStyle(myStyle)
      tell application "Adobe InDesign CS2"
      set find preferences to nothing
      set change preferences to nothing
      set theDoc to active document
      search theDoc with find attributes {applied paragraph style:myStyle}
      tell active document
      set myFoundStyles to search theDoc with find attributes {find text:""}
      if (count myFoundStyles) = 0 then
      try
      delete myStyle
      end try
      end if
      end tell
      end tell
      end RemoveUnusedStyle

      tell application "Adobe InDesign CS2"
      try
      repeat
      tell front document
      set theUnusedSwatches to unused swatches
      repeat with UnusedSwatch from 1 to count of theUnusedSwatches
      if name of (item UnusedSwatch of theUnusedSwatches) is not "" then
      try
      delete (item UnusedSwatch of theUnusedSwatches)
      end try
      end if
      end repeat
      end tell
      close front document saving (yes)
      end repeat
      end try
      end tell

      Hope you can geve me a pointer.

      Cheers,

      Kev.
        • 1. Re: deleting unused paragraph styles and swatches  ID CS2
          [Jongware] Most Valuable Participant
          That's quite obvious -- once you read the script.

          >, when I delete unused styles from the paragraph styles palette ID seems to be able to 'factor in' this 'based on' issue

          Yes, and the script does not use this build-in function (you can't, in CS2). The script searches for every style in turn, and if it hasn't been found, delete it. It should check if the style is in use as a 'Based on' in all other styles.
          • 2. Re: deleting unused paragraph styles and swatches  ID CS2
            Level 1
            Hi,

            "It should check if the style is in use as a 'Based on' in all other styles."

            Yes indeed. However, I can't find any way of referencing whether a style is being based on. Is it possible? Alternatively. is there a way of setting the 'Based on' to the default? It seems that once a style has been created, the 'Based on' setting can be changed without the formatting being lost. If the script could reset the 'Based on' settings for each paragraph styke to defaults, then delete unused, all the formatting should remain.

            Cheers,

            kev.
            • 3. Re: deleting unused paragraph styles and swatches  ID CS2
              sstanleyau Level 4
              On 27/11/08 11:25 PM, "kevin quinn" <member@adobeforums.com> wrote:<br /><br />> I can't find any way of referencing whether a style is being based on.<br /><br />Paragraph styles have a "based on" property. You'll need to get that for<br />each one, and then make sure you don't delete them.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Florida, April 2009 <a href=http://scriptingmatters.com/aspro>
              • 4. Re: deleting unused paragraph styles and swatches  ID CS2
                Level 1
                Hi Shane, thanks for that.

                However,

                'Paragraph styles have a "based on" property. You'll need to get that for
                each one, and then make sure you don't delete them.'

                could you give me some pointers as to how to do that?

                Cheers,

                Kev.
                • 5. Re: deleting unused paragraph styles and swatches  ID CS2
                  sstanleyau Level 4
                  You could get a list of them using something like:<br /><br />   set basedOnStyles to based on of paragraph styles 2 thru -1 -- skip no<br />style<br /><br />Then where you have "my RemoveUnusedStyle(myCurrentStyle)", precede it with<br />a line like:<br /><br /> if myCurrentStyle is not in basedOnStyles then<br /> my RemoveUnusedStyle(myCurrentStyle)<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Florida, April 2009 <a href=http://scriptingmatters.com/aspro>
                  • 6. Re: deleting unused paragraph styles and swatches  ID CS2
                    Level 1
                    Hi Shane, thanks for that, I really appreciate your help on this.

                    Here's the script for those who are interested:

                    tell application "Adobe InDesign CS2"
                    activate
                    set theDoc to active document
                    tell theDoc
                    repeat 3 times
                    set theUnusedSwatches to unused swatches
                    repeat with UnusedSwatch from 1 to count of theUnusedSwatches
                    if name of (item UnusedSwatch of theUnusedSwatches) is not "" then
                    try
                    delete (item UnusedSwatch of theUnusedSwatches)
                    end try
                    end if
                    set myParagraphStyles to every paragraph style of theDoc
                    set basedOnStyles to based on of paragraph styles 2 thru -1
                    set theCount to count of myParagraphStyles
                    repeat with n from (count myParagraphStyles) to 2 by -1
                    set myCurrentStyle to item n of myParagraphStyles
                    if myCurrentStyle is not in basedOnStyles then
                    my RemoveUnusedStyle(myCurrentStyle)
                    end if
                    end repeat
                    end repeat
                    end repeat
                    end tell
                    end tell
                    on RemoveUnusedStyle(myStyle)
                    tell application "Adobe InDesign CS2"
                    set find preferences to nothing
                    set change preferences to nothing
                    set theDoc to active document
                    search theDoc with find attributes {applied paragraph style:myStyle}
                    tell active document
                    set myFoundStyles to search theDoc with find attributes {find text:""}
                    if (count myFoundStyles) = 0 then
                    try
                    delete myStyle
                    end try
                    end if
                    end tell
                    end tell
                    end RemoveUnusedStyle

                    Cheers,

                    Kev.
                    • 7. Re: deleting unused paragraph styles and swatches  ID CS2
                      Level 1
                      Hi Kav,

                      Thanks for this script working fine, but can you add remove unused character style within
                      • 8. Re: deleting unused paragraph styles and swatches  ID CS2
                        Level 1
                        Hi Kav,

                        Thanks for this script working fine, but can you add remove unused character style within.

                        Shonky
                        • 9. Re: deleting unused paragraph styles and swatches  ID CS2
                          Level 1
                          Hi,

                          This script will remove unused character styles:

                          tell application "Adobe InDesign CS2"
                          activate
                          set theDoc to active document
                          tell theDoc
                          set myCharacterStyles to every character style of theDoc
                          set basedOnStyles to based on of character styles 2 thru -1
                          set theCount to count of myCharacterStyles
                          repeat with n from (count myCharacterStyles) to 2 by -1
                          set myCurrentStyle to item n of myCharacterStyles
                          if myCurrentStyle is not in basedOnStyles then
                          my RemoveUnusedStyle(myCurrentStyle)
                          end if
                          end repeat
                          end tell
                          end tell
                          on RemoveUnusedStyle(myStyle)
                          tell application "Adobe InDesign CS2"
                          activate
                          set find preferences to nothing
                          set change preferences to nothing
                          set theDoc to active document
                          search theDoc with find attributes {applied character style:myStyle}
                          tell active document
                          set myFoundStyles to search theDoc with find attributes {find text:""}
                          if (count myFoundStyles) = 0 then
                          try
                          delete myStyle
                          end try
                          end if
                          end tell
                          end tell
                          end RemoveUnusedStyle

                          I'm sorry, but I don't have the time at the moment to integrate it into the other script.

                          Hope it helps you though.

                          kev.
                          • 10. Re: deleting unused paragraph styles and swatches  ID CS2
                            Roy McCoy Level 1
                            kevin quinn wrote:

                            > This script will remove unused character styles

                            My attempt to update for CS4 failed:

                            *****

                            tell application "Adobe InDesign CS4"
                            activate
                            set theDoc to active document
                            tell theDoc
                            set myCharacterStyles to every character style of theDoc
                            set basedOnStyles to based on of character styles 2 thru -1
                            set theCount to count of myCharacterStyles
                            repeat with n from (count myCharacterStyles) to 2 by -1
                            set myCurrentStyle to item n of myCharacterStyles
                            if myCurrentStyle is not in basedOnStyles then
                            my RemoveUnusedStyle(myCurrentStyle)
                            end if
                            end repeat
                            end tell
                            end tell
                            on RemoveUnusedStyle(myStyle)
                            tell application "Adobe InDesign CS4"
                            activate
                            set find text preferences to nothing
                            set change text preferences to nothing
                            set theDoc to active document
                            set applied character style of find text preferences to myStyle
                            find text theDoc
                            set find text preferences to nothing
                            set applied character style of find text preferences to myStyle
                            tell active document
                            set myFoundStyles to find text theDoc
                            if (count myFoundStyles) = 0 then
                            try
                            delete myStyle
                            end try
                            end if
                            end tell
                            end tell
                            end RemoveUnusedStyle

                            *****

                            The first time I ran it it left one of the two unused styles I'd
                            created undeleted, and the second time it generated the AppleScript
                            error 'Cant make «class csty» id 357 of document "Untitled-15.indd"
                            of application "Adobe InDesign CS4" into type Unicode text'
                            highlighting "myCurrentStyle" in the if line of the repeat.


                            Thanks,

                            Roy McCoy
                            Rotterdam, NL
                            • 11. Re: deleting unused paragraph styles and swatches  ID CS2
                              Level 1
                              Hi,

                              Can't help, I'm afraid. Clearly something's in ID's Applescript dictionary between CS2 and 4, but I've only got CS2. You could try posting on the Macscripter.net Applescript forum; they're usually pretty helpful.

                              Cheers,

                              kev.
                              • 12. Re: deleting unused paragraph styles and swatches  ID CS2
                                sstanleyau Level 4
                                On 16/12/08 1:06 AM, "Roy McCoy" <member@adobeforums.com> wrote:<br /><br />> set find text preferences to nothing<br />> set applied character style of find text preferences to myStyle<br />> tell active document<br /><br />Those lines look redundant.<br /><br />> The first time I ran it it left one of the two unused styles I'd<br />> created undeleted<br /><br />This script is not foolproof, in that it won't delete any character style<br />that's based on another, even if the one it's based on is not used.<br /><br />> and the second time it generated the AppleScript<br />> error 'Can¹t make «class csty» id 357 of document "Untitled-15.indd"<br />> of application "Adobe InDesign CS4" into type Unicode text'<br />> highlighting "myCurrentStyle" in the if line of the repeat.<br /><br />No idea how you got that.<br /><br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Florida, April 2009 <a href=http://scriptingmatters.com/aspro>
                                • 13. Re: deleting unused paragraph styles and swatches  ID CS2
                                  Level 1
                                  Thanks Kav,

                                  It working with cs2

                                  Regards,
                                  Shonky
                                  • 14. Re: deleting unused paragraph styles and swatches  ID CS2
                                    Muthuraj Durairaj Level 1

                                    Hi SStanleyau,

                                     

                                    This is an excellent work and this is what exactly I am looking for. But I am using windows XP and Indesign CS4. Could you please convert this applescript into Javascript. That would be a great help. Thanks.

                                    • 15. Re: deleting unused paragraph styles and swatches  ID CS2
                                      nellbern

                                      I'm using the script above for CS 4 & I't is not compiling

                                       

                                      A plural class name can’t go after this identifier.

                                       

                                      It stops at this line

                                      set find preferences to nothing