【问题标题】:Multiple conditional using AppleScript in Indesign -- won't work?在 Indesign 中使用 AppleScript 的多个条件 - 行不通?
【发布时间】:2014-11-21 04:26:53
【问题描述】:

这让我失去理智。这是我试图开始工作的代码的简短版本。它返回奇怪的值并在随机高度和宽度设置时给我错误。我一辈子都想不通我哪里错了!我认为我确定输入的逻辑门是坚如磐石的!任何帮助将不胜感激!

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

【问题讨论】:

  • 对预期结果和实际错误消息的描述会有所帮助。
  • 当我将高度和宽度设置为“5”时,它以 25% 的比例大小返回。即使我删除了所有其他 if-then 语句并只说“如果 bigDim ≤ 216 然后将 buildSize 设置为“1”,它也不起作用。它只是说 buildSize 没有定义——这只会发生在我的输入是 > 216。这毫无意义!

标签: applescript adobe-indesign


【解决方案1】:

你写

    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 足够聪明,可以将两个值都转换为数字,因为将两个字符串分开是没有意义的;-)

享受吧,迈克尔/汉堡

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-07
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    • 2013-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多