8 Replies Latest reply on Jun 25, 2014 7:20 AM by nellbern

    Not compiling

    nellbern Level 1

      The following will batch ID files but it is not compiling.

      Here is i want to achieve: Change doc prefs to inches, resize, bleeds, no slug, master margins, delete all unused masters, unlock-delete some layers & load master pages templates. The load master pages templates is not compiling. my brain is fried & i can't see where the error is

       

      try

        with timeout of 3600 seconds --1HR

       

        set source_folder to choose folder with prompt "Select folder containing Indesign Documents to batch"

        tell application "Finder" to set theFiles to files of source_folder whose name extension is "indd"

       

        end timeout

       

      on error number -1712 -- the comand time out, so cancel the script

        tell application "System Events"

        tell application process "Finder"

        click button "Cancel" of window "Choose a Folder"

        end tell

        end tell

        error number -128 --throw a user cancelled error

      end try

       

      repeat with oneFile in theFiles

        tell application "Adobe InDesign CS4"

        set user interaction level of script preferences to never interact

        activate

        set myDocument to open (oneFile as alias)

        tell myDocument

       

        --++++++++++++++++

        tell view preferences

        set ruler origin to page origin

        set horizontal measurement units to inches

        set vertical measurement units to inches

        end tell

       

        --tell document preferences

        tell document preferences

        --Change current DocSize

        set page width to "7.9375 in"

        set page height to "9.75 in"

        --bleed and slug

        set document bleed bottom offset to ".25 in"

        set document bleed top offset to ".25 in"

        set document bleed inside or left offset to ".25 in"

        set document bleed outside or right offset to ".25 in"

        set slug bottom offset to "0"

        set slug top offset to "0"

        set slug inside or left offset to "0"

        set slug right or outside offset to "0"

        end tell

       

        --delete Unused Master pages- delete used Master

        set moreMasters to {}

        tell application "Adobe InDesign CS4"

        repeat with i from 1 to count of documents

        tell document i

        set allMasters to every master spread

        set theMasters to applied master of every page

        repeat with x in theMasters

        set end of moreMasters to applied master of x

        end repeat

        set theMasters to theMasters & moreMasters

        repeat with x in allMasters

        if x is not in theMasters then delete x

        end repeat

        if (exists (master spread "Z-OMX Master")) and (count master spreads) > 1 then delete master spread "Z-OMX Master"

        end tell

        end repeat

        end tell

       

       

        --change margins of the master spread

        set myMasterSpread to master spread 1

        tell margin preferences of page 1 of myMasterSpread

        -- page margins and columns.

        set top to ".25 in"

        set bottom to ".5 in"

        set left to ".5" --inside

        set right to ".75 in" --outside

        set column count to 2

        set column gutter to 0.279

       

        end tell

        --Page margins master page for the right-hand page.

        tell margin preferences of page 2 of myMasterSpread

        set top to ".25 in"

        set bottom to ".5 in"

        set left to ".5" --inside

        set right to ".75 in" --outside

        set column count to 2

        set column gutter to 0.279

        end tell

       

        delete guides

       

        --unlock/colorize

        tell guide preferences

        set guides locked to false

        set ruler guides color to cyan

        end tell

       

        --make guides on Master Pages

        tell myMasterSpread's page 1

        make guide with properties {orientation:vertical, location:0.25}

        make guide with properties {orientation:vertical, location:7.6875}

        make guide with properties {orientation:horizontal, location:0.5}

        make guide with properties {orientation:horizontal, location:9.5}

        end tell

        tell myMasterSpread's page 2

        make guide with properties {orientation:vertical, location:0.25}

        make guide with properties {orientation:vertical, location:7.6875}

        make guide with properties {orientation:horizontal, location:0.5}

        make guide with properties {orientation:horizontal, location:9.5}

        end tell

       

       

      --load Master template 

      set docRef to document 1 of application "Adobe InDesign CS4"

      set templatePath to "Macintosh HD:Applications:Adobe InDesign CS4:Templates:Maxi_Templates.indd"

       

      (*Boolean if false indicates master spreads should be renamed in case of name clash*)

      loadMasters(docRef, templatePath, false)

      tell application "Adobe InDesign CS4"

        set templatePath to file path as string

        --set templatePath to "Macintosh HD:Applications:Adobe InDesign CS4:Templates:Maxi_Templates.indd"

      end tell

       

       

      (*Loads master spreads from referenced document.*)

      on loadMasters(docRef, filePath, doOverwrite)

        tell application "Adobe InDesign CS4"

        tell docRef

        if doOverwrite = true then

        load masters from filePath global strategy for master page load all with overwrite

        else

        load masters from filePath global strategy for master page load all with rename

        end if

        end tell

        end tell

      end loadMasters

       

       

        --+++

        --display dialog "" buttons {"Cancel"} default button 1

        --+++

       

        close myDocument saving yes

        end tell

        set user interaction level of script preferences to interact with all

       

        end tell

      end repeat

       

       

       

      beep 5

      with timeout of 10000 seconds

        tell application "Finder"

        activate

        --display dialog "DONE" buttons {" :-) OK"} with icon 1 default button 1 giving up after 15

        --display dialog "Done, check the links" with icon path to resource "ID_App_Icon.icns" in bundle (path to application "Adobe InDesign CS4")

        display dialog "DONE" buttons {" :-) OK"} giving up after 15 with icon path to resource "ID_App_Icon.icns" in bundle (path to application "Adobe InDesign CS4") --giving up after 15

       

        end tell

      end timeout

        • 1. Re: Not compiling
          Dirk Becker Level 4

          You're telling too much

           

          Seriously, that method declaration "on loadMasters" should not go into the tell clause, methods better stay top level. I moved it to the top of the script.

          You can also eliminate a few nested "tell application InDesign", and to make things clear wrap the whole script into an explicit "on run" which is otherwise implied.

          The following compiles with my CS6, I did not test anything further.

           

          (*Loads master spreads from referenced document.*)

          on loadMasters(docRef, filePath, doOverwrite)

            tell application "Adobe InDesign CS6"

            tell docRef

            if doOverwrite = true then

            load masters from filePath global strategy for master page load all with overwrite

            else

            load masters from filePath global strategy for master page load all with rename

            end if

            end tell

            end tell

          end loadMasters

           

          on run

            try

            with timeout of 3600 seconds --1HR

            set source_folder to choose folder with prompt "Select folder containing Indesign Documents to batch"

            tell application "Finder" to set theFiles to files of source_folder whose name extension is "indd"

            end timeout

            on error number -1712 -- the comand time out, so cancel the script

            tell application "System Events"

            tell application process "Finder"

            click button "Cancel" of window "Choose a Folder"

            end tell

            end tell

            error number -128 --throw a user cancelled error

            end try

           

            tell application "Adobe InDesign CS6"

            activate

            set user interaction level of script preferences to never interact

            repeat with oneFile in theFiles

            set myDocument to open (oneFile as alias)

            tell myDocument

           

            tell view preferences

            set ruler origin to page origin

            set horizontal measurement units to inches

            set vertical measurement units to inches

            end tell

           

            tell document preferences

            --Change current DocSize

            set page width to "7.9375 in"

            set page height to "9.75 in"

            --bleed and slug

            set document bleed bottom offset to ".25 in"

            set document bleed top offset to ".25 in"

            set document bleed inside or left offset to ".25 in"

            set document bleed outside or right offset to ".25 in"

            set slug bottom offset to "0"

            set slug top offset to "0"

            set slug inside or left offset to "0"

            set slug right or outside offset to "0"

            end tell

           

            --delete Unused Master pages- delete used Master

            set moreMasters to {}

            repeat with i from 1 to count of documents

            tell document i

            set allMasters to every master spread

            set theMasters to applied master of every page

            repeat with x in theMasters

            set end of moreMasters to applied master of x

            end repeat

            set theMasters to theMasters & moreMasters

            repeat with x in allMasters

            if x is not in theMasters then delete x

            end repeat

            if (exists (master spread "Z-OMX Master")) and (count master spreads) > 1 then delete master spread "Z-OMX Master"

            end tell

            end repeat

           

            --change margins of the master spread

            set myMasterSpread to master spread 1

            tell margin preferences of page 1 of myMasterSpread

            -- page margins and columns.

            set top to ".25 in"

            set bottom to ".5 in"

            set left to ".5" --inside

            set right to ".75 in" --outside

            set column count to 2

            set column gutter to 0.279

            end tell

           

            --Page margins master page for the right-hand page.

            tell margin preferences of page 2 of myMasterSpread

            set top to ".25 in"

            set bottom to ".5 in"

            set left to ".5" --inside

            set right to ".75 in" --outside

            set column count to 2

            set column gutter to 0.279

            end tell

           

            delete guides

           

            --unlock/colorize

            tell guide preferences

            set guides locked to false

            set ruler guides color to cyan

            end tell

           

            --make guides on Master Pages

            tell myMasterSpread's page 1

            make guide with properties {orientation:vertical, location:0.25}

            make guide with properties {orientation:vertical, location:7.6875}

            make guide with properties {orientation:horizontal, location:0.5}

            make guide with properties {orientation:horizontal, location:9.5}

            end tell

           

            tell myMasterSpread's page 2

            make guide with properties {orientation:vertical, location:0.25}

            make guide with properties {orientation:vertical, location:7.6875}

            make guide with properties {orientation:horizontal, location:0.5}

            make guide with properties {orientation:horizontal, location:9.5}

            end tell

           

            --load Master template

            set docRef to document 1

            set templatePath to "Macintosh HD:Applications:Adobe InDesign CS6:Templates:Maxi_Templates.indd"

           

            (*Boolean if false indicates master spreads should be renamed in case of name clash*)

            loadMasters(docRef, templatePath, false)

            set templatePath to file path as string

            --set templatePath to "Macintosh HD:Applications:Adobe InDesign CS6:Templates:Maxi_Templates.indd"

           

            --+++

            --display dialog "" buttons {"Cancel"} default button 1

            --+++

           

            close myDocument saving yes

            end tell --- document

            end repeat

            set user interaction level of script preferences to interact with all

            end tell -- application

           

            beep 5

            with timeout of 10000 seconds

            tell application "Finder"

            activate

            --display dialog "DONE" buttons {" :-) OK"} with icon 1 default button 1 giving up after 15

            --display dialog "Done, check the links" with icon path to resource "ID_App_Icon.icns" in bundle (path to application "Adobe InDesign CS6")

            display dialog "DONE" buttons {" :-) OK"} giving up after 15 with icon path to resource "ID_App_Icon.icns" in bundle (path to application "Adobe InDesign CS6") --giving up after 15

            end tell

            end timeout

           

          end run


          • 2. Re: Not compiling
            nellbern Level 1

            Thank you Dirk. I'm getting an error:

            Adobe InDesign CS4 got an error: every document of document \"P_1.indd\" doesn’t understand the count message." number -1708 from every document of document "P_1.indd"

            • 3. Re: Not compiling
              Dirk Becker Level 4

              Like I said, I did not test any further, and you're "tell"ing too much.

              Try to remove the loop/tell over the documents, the outside tell is already adressing a document.

              The block in question looks like copy-pasted from somewhere else, it would then become

               

                --delete Unused Master pages

                set moreMasters to {}

                set allMasters to every master spread

                set theMasters to applied master of every page

                repeat with x in theMasters

                set end of moreMasters to applied master of x

                end repeat

                set theMasters to theMasters & moreMasters

                repeat with x in allMasters

                if x is not in theMasters then delete x

                end repeat


              -- fancy comment here

                if (exists (master spread "Z-OMX Master")) and (count master spreads) > 1 then delete master spread "Z-OMX Master"

              • 4. Re: Not compiling
                Dirk Becker Level 4

                The following script demonstrates some lesser known AppleScript syntax tricks.

                 

                -- address InDesign version independent, by ID.

                -- works like an implicit tell application within the methods

                property parent : application id "com.adobe.indesign"

                -- help the applescript compiler

                using terms from application "Adobe InDesign CS6"

                 

                  -- You could isolate other code blocks into similar "on …" handlers.

                  on deleteUnusedMasterSpreads(aDoc)

                  tell aDoc

                  -- build an ID list

                  set usedMasterIDs to id of applied master of every page

                  -- use "whose" to filter

                  -- store the whole expression as "reference"

                  set unusedMasterSpreads to a reference to (master spreads whose id is not in usedMasterIDs)

                  -- unfortunately, delete does not ignore the empty list

                  if exists unusedMasterSpreads then

                  delete unusedMasterSpreads

                  end if

                  end tell -- aDoc

                  end deleteUnusedMasterSpreads

                 

                  on run

                  deleteUnusedMasterSpreads(document 1)

                  end run

                 

                end using terms from


                • 5. Re: Not compiling
                  nellbern Level 1

                  You are absolutely right I copied the code from someone. I have some knowledge in AS but not good enough to build code from scratch. That is the consequence  of copying code but that's why I posted here so people like you can help me

                  • 6. Re: Not compiling
                    nellbern Level 1

                      How do apply the [None] master to all Master page? I tried this line & Im getting an error:

                    Invalid value for set property 'applied master'. Expected master spread or nothing, but received nothing." number 30477


                    set applied master of every master spread to master spread "[None]"

                    • 7. Re: Not compiling
                      Dirk Becker Level 4

                      Please mark this thread as answered if your original problem is solved, then open a separate thread per different question. It also helps to find AppleScript questions if you use an [AS] in the subject line.

                      • 8. Re: Not compiling
                        nellbern Level 1

                        I did marked as answered. Thanks for your help