0
votes

I am working on finishing up an script droplet to pull all used swatches out of multiple indesign documents that I drop on the script and list them. I am adapting this from a script I wrote to put all used swatches from a single file.

I have the basics down but have run into two problems and cant find an answer.

Problem 1: I need to add the line to "repeat until swatchCount < 2" but this would ad a repeat inside a repeat. Doesn't work.

Problem 2: (the biggest problem) The "colorList" needs to add the colors from each of the documents together into a single list. Since I have it on repeat it is only listing the colors from the last processed file. How do I have the list save each files color and then list them all?

I would appreciate any help I have hit a wall.

on open these_items

    repeat with i from 1 to the count of these_items
        set this_item to item i of these_items
        set the item_info to info for this_item
        set this_item to POSIX path of this_item

        tell application "Adobe InDesign CC"
            open this_item

            tell active document
                delete unused swatches
                set allSwatches to every swatch
            end tell
            set swatchCount to count of allSwatches
            set colorList to ""
            -- repeat until swatchCount < 2
            set thisSwatch to item swatchCount of allSwatches

            try
                set swatchProps to type of thisSwatch
                set swatchProps to "Gradient"
            on error
                set swatchProps to "Color"
            end try

            if swatchProps = "Color" then

                set swatchName to name of thisSwatch as string
                set swatchType to model of thisSwatch as string
                set swatchSpace to space of thisSwatch as string
                set swatchColor to color value of thisSwatch

                if swatchType contains "spot" then
                    set swatchType to "Spot"
                else
                    if swatchType contains "prss" then
                        set swatchType to "Process"
                    end if
                end if

                if swatchSpace contains "RGB" then
                    set rrr to ((item 1 of swatchColor) as integer)
                    set ggg to ((item 2 of swatchColor) as integer)
                    set bbb to ((item 3 of swatchColor) as integer)
                    set swatchMix to (" value: R-" & rrr & "  G-" & ggg & "  B-" & bbb) as string

                    if swatchName does not contain "registration" then
                        set swatchItem to "Name: " & swatchName & swatchMix & " space: RGB" & " type: " & swatchType & return
                    else
                        set swatchItem to ""
                    end if
                else
                    if swatchSpace contains "CMYK" then
                        set ccc to ((item 1 of swatchColor) as integer)
                        set mmm to ((item 2 of swatchColor) as integer)
                        set yyy to ((item 3 of swatchColor) as integer)
                        set kkk to ((item 4 of swatchColor) as integer)
                        set swatchMix to (" value: C-" & ccc & "  M-" & mmm & "  Y-" & yyy & "  K-" & kkk) as string

                        if swatchName does not contain "registration" then
                            set swatchItem to "Name: " & swatchName & swatchMix & " space:CMYK" & " type: " & swatchType & return
                        else
                            set swatchItem to ""
                        end if
                    else
                        if swatchSpace contains "LAB" then
                            set lll to ((item 1 of swatchColor) as integer)
                            set aaa to ((item 2 of swatchColor) as integer)
                            set bbb to ((item 3 of swatchColor) as integer)

                            set swatchMix to (" value: L-" & lll & "  A-" & aaa & "  B-" & bbb) as string

                            if swatchName does not contain "registration" then
                                set swatchItem to "Name: " & swatchName & swatchMix & " space: LAB" & " type: " & swatchType & return
                            else
                                set swatchItem to ""
                            end if
                        end if
                    end if
                end if

                set colorList to colorList & swatchItem
            end if

            tell active document to close saving no
            set swatchCount to swatchCount - 1

            --end repeat
        end tell

    end repeat



    set dragged_items to these_items as string
    set old_delimiters to AppleScript's text item delimiters
    set AppleScript's text item delimiters to {":"}

    set theClientName to text item 2 of dragged_items
    set theFileName to text item 5 of dragged_items

    set AppleScript's text item delimiters to old_delimiters

    set theOrderNumber to text 1 through 5 of theFileName
    set headerInfo to "Client: " & theClientName & "        Order # " & theOrderNumber & "      File: " & theFileName
    tell application "Adobe InDesign CC"
        tell view preferences
            set horizontal measurement units to inches
            set vertical measurement units to inches
        end tell
        make new document with properties {document preferences:{page width:8.5, page height:11}}
        tell view preferences
            set horizontal measurement units to inches
            set vertical measurement units to inches
        end tell
        tell active document
            set zero point to {0, 0}
            set properties of guide preferences to {guides shown:false}
            set properties of text preferences to {show invisibles:false}
            set properties of view preferences to {ruler origin:page origin, horizontal measurement units:inches, show frame edges:false, show rulers:true, vertical measurement units:inches}
            tell layout window 1
                zoom given fit page
                set properties to {view display setting:typical, transform reference point:top left anchor}
            end tell

            make new text frame with properties {geometric bounds:{0.5, 0.5, 0.75, 8.0}, contents:headerInfo, color:"None"}

            set paragraphCount to count of paragraphs of colorList
            repeat until paragraphCount > 19
                set colorList to colorList & "name: _________________________" & "  value: ____________________" & "    space: ______" & "  type: _________" & return
                set paragraphCount to count of paragraphs of colorList
            end repeat

            make new text frame with properties {geometric bounds:{4.5, 0.5, 20.0, 8.0}, contents:colorList, color:"None"}

            tell text frame 1
                tell every text to set point size to 10
                tell every paragraph
                    make tab stop with properties {alignment:left align, position:2.875}
                    make tab stop with properties {alignment:left align, position:5.125}
                    make tab stop with properties {alignment:left align, position:6.375}
                end tell
                set geometric bounds to {1.0, 0.5, 11, 8.0}
            end tell
        end tell
    end tell

end open

on run
    --  Handle the case where the script is launched without any dropped files
    open (choose file with multiple selections allowed)
end run

I have added the changes that you suggested "Darrick Herwehe" but am getting an error now on a different part.

Can’t get name of color id 344 of document id 30
--name of color id 344 of document id 29 of application "Adobe InDesign CC"--

getting this in reference to: set swatchName to name of thisSwatch on open these_items set colorList to "" set swatchItem to ""

repeat with i from 1 to the count of these_items

    --Get swatches from document start
    set this_item to item i of these_items
    set the item_info to info for this_item
    set this_item to POSIX path of this_item

    tell application "Adobe InDesign CC"
        open this_item

        tell active document
            delete unused swatches
            set allSwatches to every swatch
        end tell
        set swatchCount to count of allSwatches

        repeat until swatchCount < 2

            repeat with j from 1 to (count allSwatches)
                set thisSwatch to item swatchCount of allSwatches

                try
                    set swatchProps to type of thisSwatch
                    set swatchProps to "Gradient"
                on error
                    set swatchProps to "Color"
                end try

                if swatchProps = "Color" then
                                            set swatchName to name of thisSwatch
                    set swatchType to model of thisSwatch
                    set swatchSpace to space of thisSwatch
                    set swatchColor to color value of thisSwatch

                    if swatchType contains "spot" then
                        set swatchType to "Spot"
                    else
                        if swatchType contains "prss" then
                            set swatchType to "Process"
                        end if
                    end if

                    if swatchSpace contains "RGB" then
                        set rrr to ((item 1 of swatchColor) as integer)
                        set ggg to ((item 2 of swatchColor) as integer)
                        set bbb to ((item 3 of swatchColor) as integer)
                        set swatchMix to (" value: R-" & rrr & "  G-" & ggg & "  B-" & bbb) as string

                        if swatchName does not contain "registration" then
                            set swatchItem to "Name: " & swatchName & swatchMix & " space: RGB" & " type: " & swatchType & return
                        else
                            set swatchItem to ""
                        end if
                    else
                        if swatchSpace contains "CMYK" then
                            set ccc to ((item 1 of swatchColor) as integer)
                            set mmm to ((item 2 of swatchColor) as integer)
                            set yyy to ((item 3 of swatchColor) as integer)
                            set kkk to ((item 4 of swatchColor) as integer)
                            set swatchMix to (" value: C-" & ccc & "  M-" & mmm & "  Y-" & yyy & "  K-" & kkk) as string

                            if swatchName does not contain "registration" then
                                set swatchItem to "Name: " & swatchName & swatchMix & " space:CMYK" & " type: " & swatchType & return
                            else
                                set swatchItem to ""
                            end if
                        else
                            if swatchSpace contains "LAB" then
                                set lll to ((item 1 of swatchColor) as integer)
                                set aaa to ((item 2 of swatchColor) as integer)
                                set bbb to ((item 3 of swatchColor) as integer)

                                set swatchMix to (" value: L-" & lll & "  A-" & aaa & "  B-" & bbb) as string

                                if swatchName does not contain "registration" then
                                    set swatchItem to "Name: " & swatchName & swatchMix & " space: LAB" & " type: " & swatchType & return
                                else
                                    set swatchItem to ""
                                end if
                            end if
                        end if
                    end if
                    tell active document to close saving no
                    set colorList to colorList & swatchItem
                end if


                set swatchCount to swatchCount - 1

            end repeat
        end repeat
    end tell

end repeat



set dragged_items to these_items as string
set old_delimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}

set theClientName to text item 2 of dragged_items
set theFileName to text item 5 of dragged_items

set AppleScript's text item delimiters to old_delimiters

set theOrderNumber to text 1 through 5 of theFileName
set headerInfo to "Client: " & theClientName & "        Order # " & theOrderNumber & "      File: " & theFileName
tell application "Adobe InDesign CC"
    tell view preferences
        set horizontal measurement units to inches
        set vertical measurement units to inches
    end tell
    make new document with properties {document preferences:{page width:8.5, page height:11}}
    tell view preferences
        set horizontal measurement units to inches
        set vertical measurement units to inches
    end tell
    tell active document
        set zero point to {0, 0}
        set properties of guide preferences to {guides shown:false}
        set properties of text preferences to {show invisibles:false}
        set properties of view preferences to {ruler origin:page origin, horizontal measurement units:inches, show frame edges:false, show rulers:true, vertical measurement units:inches}
        tell layout window 1
            zoom given fit page
            set properties to {view display setting:typical, transform reference point:top left anchor}
        end tell

        make new text frame with properties {geometric bounds:{0.5, 0.5, 0.75, 8.0}, contents:headerInfo, color:"None"}

        set paragraphCount to count of paragraphs of colorList
        repeat until paragraphCount > 19
            set colorList to colorList & "name: _________________________" & "  value: ____________________" & "    space: ______" & "  type: _________" & return
            set paragraphCount to count of paragraphs of colorList
        end repeat

        make new text frame with properties {geometric bounds:{4.5, 0.5, 20.0, 8.0}, contents:colorList, color:"None"}

        tell text frame 1
            tell every text to set point size to 10
            tell every paragraph
                make tab stop with properties {alignment:left align, position:2.875}
                make tab stop with properties {alignment:left align, position:5.125}
                make tab stop with properties {alignment:left align, position:6.375}
            end tell
            set geometric bounds to {1.0, 0.5, 11, 8.0}
        end tell
    end tell
end tell

end open

on run -- Handle the case where the script is launched without any dropped files open (choose file with multiple selections allowed) end run

If you have any insight I would much appriciate it. Thanks again Matt

1

1 Answers

2
votes

You can nest repeat loops. It's not a problem, it's done all the time. You just have to define a different iteration variable from your first repeat loop. In your case, I would use j.

As for getting all of the colors into one list, you neeed to define colorList outside your first repeat loop. That way it doesn't get overwritten during each iteration.

An outline for that would be:

on open these_items
    set colorList to ""
    repeat with i from 1 to the count of these_items
        -- [ Get swatches from the document ]
        repeat with j from 1 to (count allSwatches)
            -- [ Process your swatches ]
            set colorList to colorList & swatchItem
        end repeat
    end repeat
end open