Trigger Handler twice in Applescript results in error

末鹿安然 提交于 2019-12-25 02:10:44

问题


so i written this code so far, it works very well, the only issue is, calling the code twice results with an error «script» doesn’t understand the Remi message. (-1708)

Whats to point here and how can i unset the handler after it was triggered?

The Code:

my Remi()

on Remi()
    set cD to (current date)

    tell application "Reminders"
        --set output to name of reminders
        if (count of (reminders whose completed is false)) > 0 then
            set output to ""
            set todoList to name of reminders whose completed is false
            repeat with itemNum from 1 to ((count of (reminders whose completed is false)))
                try
                    set Remi to item itemNum of reminders
                    set remiT to due date of Remi
                    set tim to time string of remiT
                    set dD to date string of remiT
                    set nN to name of Remi
                    if remiT ≤ cD then
                        set val to (tim & " - " & nN & " $$" & dD & "/ENDE")
                        set output to (output & val & return)
                    end if
                end try
            end repeat
        else
            set output to "No reminders available"
        end if
    end tell
    return output
end Remi

Thx for help


回答1:


I see what is causing the problem. You have a variable "Remi" inside the "Remi()" handler. I guess you can't do that! So either change the name of the variable or the name of the handler and you should be good.




回答2:


The problem is caused by the set Remi to item itemNum of reminders statement which changes the value of the remi global variable from a handler to whatever `item itemNum of reminders' turns out to be. The second time through, when you ask AppleScript to call the Remi handler, it is no longer handler and so the call fails.

You can change your code to not alter the global Remi variable, or you can declare Remi local within the handler using a local Remi statement. This protects the global version of Remi from alteration.



来源:https://stackoverflow.com/questions/13240603/trigger-handler-twice-in-applescript-results-in-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!