2 Replies Latest reply on Oct 29, 2012 8:15 PM by Abhi_apple

    How to change dictionary in Indesign by Apple Scripting

    Abhi_apple

      Hi Friends,

       

      I am new to Indesign Scripting through Apple Script.

       

      I was trying to work on a script which can basically change my default setting of dictionary in Indesign to "English: USA" when we go to Indesign---> Preferences---> Dictionary

       

      I was trying the below code in AppleScript.

       

      tell application "Adobe InDesign CS4"

                tell document preferences of dictionary

                          set language name of document preferences to "English: USA"

                end tell

      end tell

       

      However, it is showing error.

       

      Would appreciate if you can guide and suggest the correct way.

       

      Also, in character styling (please see below screen-shot) I need to change my dictionary to "English: USA". Please suggest if this is possible to achieve by AppleScript.

       

      Image.png

       

      Thanks for your help and suggestion!

       

      Regards,

       

      Abhishek

        • 1. Re: How to change dictionary in Indesign by Apple Scripting
          tobias.wantzen Level 1

          Hi Abhishek,

           

          below you'll find the script I'm using for changing the language of styles (based on Oliver Berquin's script as documented).

           

          Cheers

          Tobias

           

           

          -- http://olivier.berquin.free.fr/indesign/indesign_cs1.html#top_Change_language
          
          
          tell application "Adobe InDesign CS5.5"
            activate
                    if (count documents) = 0 then
            display dialog "Please, open a document" buttons "OK" default button 1 with icon caution
                    else
                              set myDocument to active document
            
                              set listOfLanguage to name of every language with vendors
                              my Qsort(listOfLanguage, 1, (count listOfLanguage))
            
                              set myDialog to make dialog with properties {name:"Change the Langage of All Styles"}
                              tell myDialog
                                        tell (make dialog column)
                                                  tell (make border panel)
                                                            tell (make dialog column)
            make static text with properties {static label:"Change to :"}
                                                            end tell
                                                            tell (make dialog column)
                                                                      set myLanguage to make dropdown with properties {string list:listOfLanguage, selected index:5}
                                                            end tell
                                                  end tell
                                        end tell
                              end tell
            
            -- Display the dialog box.
                              set myResult to show myDialog
            
                              if myResult is true then
            -- Get the values from the dialog box controls
                                        set TargetLanguage to (item ((selected index of myLanguage) + 1)) of listOfLanguage
            
                                        tell myDocument
            
                                                  set ListOfParagraphStyle to all paragraph styles -- whose name is not "[No Paragraph Style]"
                                                  set ListOfCharacterStyle to all character styles -- whose name is not "[No Character Style]"
            
                                                  set myCounter to (count of ListOfParagraphStyle) + (count of ListOfCharacterStyle)
            
                                                  if myCounter is not equal to 0 then
                                                            if (count of ListOfParagraphStyle) is not equal to 0 then
                                                                      repeat with anItem in ListOfParagraphStyle
                                                                                try
                                                                                          set applied language of anItem to TargetLanguage
                                                                                          log (name of anItem) as string
                                                                                end try
                                                                      end repeat
                                                            end if
                                                            if (count of ListOfCharacterStyle) is not equal to 0 then
                                                                      repeat with anItem in ListOfCharacterStyle
                                                                                if (applied language of anItem) ≠ nothing then
                                                                                          log (name of anItem) as string
                                                                                          set applied language of anItem to TargetLanguage
                                                                                end if
                                                                      end repeat
                                                            end if
                                                  end if
            
            
                                                  try
                                                            set applied language of every text of every text frame of every page to TargetLanguage
                                                  end try
            
                                                  try
                                                            set applied language of every text of every cell of every table of every text frame of every page to TargetLanguage
                                                  end try
            
                                        end tell
            display dialog "Done" buttons "OK" default button 1
            
                              end if
            
            -- Remove the dialog box from memory.
            destroy myDialog
            
                    end if
          end tell
          
          
          
          on Qsort(array, leftEnd, rightEnd) -- Hoare's QuickSort Algorithm
                    script a
                              property l : array
                    end script
                    set {i, j} to {leftEnd, rightEnd}
                    set v to item ((leftEnd + rightEnd) div 2) of a's l -- pivot in the middle
                    repeat while (j > i)
                              repeat while (item i of a's l < v)
                                        set i to i + 1
                              end repeat
                              repeat while (item j of a's l > v)
                                        set j to j - 1
                              end repeat
                              if (not i > j) then
                                        tell a's l to set {item i, item j} to {item j, item i} -- swap
                                        set {i, j} to {i + 1, j - 1}
                              end if
                    end repeat
                    if (leftEnd < j) then Qsort(a's l, leftEnd, j)
                    if (rightEnd > i) then Qsort(a's l, i, rightEnd)
          end Qsort
          
          
          • 2. Re: How to change dictionary in Indesign by Apple Scripting
            Abhi_apple Level 1

            Hi Tobias,

             

            Thanks for your response.

             

            I will check this script.

             

            Regards,

             

            Abhishek