【问题标题】:AppleScript repeat loop can't be re-executed without closing scriptAppleScript 重复循环不能在不关闭脚本的情况下重新执行
【发布时间】:2016-01-08 16:14:34
【问题描述】:

使用 AppleScript 我发现当你构建一个 repeat 以增加一个块时,如果你取消它,你必须关闭脚本才能重新开始:

property foobar : 0

tell application "BBEdit"
    activate
    select insertion point before first character of text document 1
    repeat
        ## some magic       
    end repeat
end tell

有没有办法取消你可以将脚本中的property 重置为 0,以便它可以再次重新运行?此外,当重复循环运行并完成时,您仍然必须关闭脚本才能重新运行它,即使在使用 set foobar to 0foobar 设置回 0 之后也是如此。研究没有显示任何关于 Apple.se、SO、超级用户或 Apple 讨论的内容。如何在不关闭脚本的情况下重置脚本?

【问题讨论】:

    标签: applescript repeat bbedit


    【解决方案1】:

    你可以这样做,你会被提示重新启动或取消脚本。

    property foobar : 0
    
    tell application "BBEdit"
        activate
        repeat
            set foobar to 0
            select insertion point before first character of text document 1
            repeat
                ## some magic       
            end repeat
            display dialog "Restart Script" buttons {"Cancel", "Restart"} default button 2
        end repeat
    end tell
    

    【讨论】:

    • 可以,只要 BBEdit 保持在最前面。
    • 对不起,这不起作用,它所执行的所有步骤都会提示您是否要重新启动它。
    • 然后删除display dialog这一行,但考虑到你会陷入死循环。
    【解决方案2】:

    我对你在脚本后面需要什么属性property foobar : 0 感到困惑。如果你只是不让它成为一个属性,它会在你每次运行脚本时重置,所以你没有问题......但我觉得我必须遗漏一些东西。

    我的意思是,为了让 foobar 成为 Applescript 属性,而不是仅仅将其定义为变量,在运行之间需要保留什么?

        set foobar to 0
    

    让我知道我在这里缺少什么......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-29
      • 1970-01-01
      • 1970-01-01
      • 2013-05-19
      • 2013-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多