首页 > 解决方案 > 为什么我的 Applescript 循环几乎总是失败?奇怪的是,它有时有效

问题描述

下面的代码用于在 TextEdit 中运行示例文本。大约有 14 次迭代,循环可能在其中任何一次中失败。以下是脚本的更新简化版本。它仍然给我同样的问题

将新图像中的代码与对话框结果进行比较

set AppleScript's text item delimiters to ":"

    tell application "TextEdit"
        activate
        tell the front document
            set nameList to the first paragraph
            set remindersList to {}
            set lineCount to count the paragraphs
            repeat with i from 2 to lineCount
                set reminderName to paragraph i
                set end of remindersList to reminderName
            end repeat
        end tell
    end tell

    tell application "Reminders"
        set newList to make new list
        set name of newList to nameList
        set reminderDate to date
        set listAccount to account
        lineCount = lineCount - 2
        repeat with i from 1 to lineCount
            tell list nameList                  
                set newremin to make new reminder
                set reminderName to item i of remindersList
                set {remName, remBody1, remBody2} to {text item 1, text item 2, text item 3} of reminderName
                set name of newremin to remName
                set body of newremin to remBody1 & return & remBody2
                set due date of newremin to (current date) + (1 * days)
            end tell
        end repeat
    end tell

    set AppleScript's text item delimiters to ""

标签: loopsapplescriptreminders

解决方案


推荐阅读