Applescript indesign列出来自多个文件的所有颜色样本

时间:2013-10-16 21:42:38

标签: applescript

我正在努力完成一个脚本Droplet,从我放在脚本上的多个indesign文档中提取所有使用过的样本并列出它们。我正在从我编写的脚本中调整它以将所有使用过的样本放在一个文件中。

我掌握了基础知识,但遇到了两个问题,无法找到答案。

问题1:我需要将行添加到“重复直到swatchCount< 2”,但这会在重复内部重复。不起作用。

问题2 :(最大的问题)“colorList”需要将每个文档的颜色一起添加到一个列表中。由于我重复它,它只列出上次处理文件的颜色。如何让列表保存每个文件颜色,然后将它们全部列出?

我很感激我的帮助。

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

我添加了您建议的“Darrick Herwehe”的更改,但现在又出现了错误。

无法获取文档ID 30的颜色ID 344的名称 - 应用程序“Adobe InDesign CC” -

的文档ID 29的颜色ID 344的名称

参考以下内容:将swatchName设置为thisSwatch的名称 打开these_items     将colorList设置为“”     将swatchItem设置为“”

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

结束

跑步      - 处理启动脚本而不删除任何文件的情况     打开(选择允许多个选择的文件) 结束

如果你有任何见解我会非常喜欢它。 再次感谢 马特

1 个答案:

答案 0 :(得分:2)

您可以嵌套重复循环。这不是问题,它一直在做。您只需要从第一个重复循环中定义一个不同的迭代变量。在您的情况下,我会使用j

至于将所有颜色放入一个列表中,您需要在第一个重复循环之外定义colorList。这样,在每次迭代过程中都不会被覆盖。

大纲是:

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