Indesign中使用AppleScript的多个条件 - 不起作用?

时间:2014-11-19 01:45:20

标签: applescript adobe-indesign

这让我失去理智。这是我试图开始工作的代码的简短版本。它返回奇怪的值并在随机高度和宽度设置中给出错误。我不能为我的生活找出错误的地方!我认为我的逻辑门确定输入是坚如磐石的!任何帮助将不胜感激!

tell application "Adobe InDesign CS6"
    activate
    set myDoc to active document

    set origLevel to user interaction level of script preferences
    set user interaction level of script preferences to interact with all

    set myDialog to make dialog with properties {name:"Make Template", can cancel:true}
    tell myDialog
        tell (make dialog column)
            tell (make border panel)
                tell (make dialog column)
                    make static text with properties {static label:"Width:", min width:60}
                    make static text with properties {static label:"Height:", min width:60}
                    make static text with properties {static label:"Bleed:", min width:60}
                end tell
                tell (make dialog column)
                    set myWidth to make text editboxes with properties {edit contents:"", min width:60}
                    set myHeight to make text editboxes with properties {edit contents:"", min width:60}
                    set myBleed to make text editboxes with properties {edit contents:"", min width:60}
                end tell
                tell (make dialog column)
                    make static text with properties {static label:"in", min width:0}
                    make static text with properties {static label:"in", min width:0}
                    make static text with properties {static label:"in", min width:0}
                end tell
                tell (make dialog column)
                    make static text with properties {static label:"", min width:25}
                end tell
            end tell
        end tell
    end tell

    set userResponse to show myDialog
    if userResponse is true then
        set docWidth to edit contents of myWidth as string
        set docHeight to edit contents of myHeight as string
        set docBleed to edit contents of myBleed as string
        destroy myDialog
    else
        destroy myDialog
        error number -128
    end if

    tell myDoc

        if docHeight > docWidth then
            set bigDim to docHeight
        else
            set bigDim to docWidth
        end if

        if bigDim ≤ 216 then
            set buildSize to "1"
        else if bigDim > 216 and bigDim ≤ 432 then
            set buildSize to "2"
        else if bigDim > 432 and bigDim ≤ 864 then
            set buildSize to "4"
        else if bigDim > 864 and bigDim ≤ 2160 then
            set buildSize to "10"
        end if

        set newWidth to (docWidth / buildSize)
        set newHeight to (docHeight / buildSize)
        set newBleed to (docBleed / buildSize)

        set document bleed top offset of document preferences to newBleed
        set page width of document preferences to newWidth
        set page height of document preferences to newHeight

    end tell

    set user interaction level of script preferences to origLevel
end tell

1 个答案:

答案 0 :(得分:0)

你写

    set docWidth to edit contents of myWidth as string
    set docHeight to edit contents of myHeight as string

实际上你将一个字符串与一个整数进行比较:if bigDim ≤ 216 then。要处理你的代码,Applescript必须转换其中一个值,看起来它将值216转换为字符串“216”。使用字符串比较,字符串“5”大于“216”并且符合比较else if bigDim > 432 and bigDim ≤ 864 then,因为字符串“5”适合“432”和“864”之间。

如何将编辑内容转换为整数?

    set docWidth to edit contents of myWidth as integer
    set docHeight to edit contents of myHeight as integer

顺便说一下,你的脚本中后面使用的代码set newWidth to (docWidth / buildSize)只是因为Applescript足够聪明,可以将两个值都转换为数字,因为除了两个字符串是没有意义的; - )

享受,迈克尔/汉堡