如何使用 AppleScript 获取今天的数量提醒?

How to get the quantity today reminders using AppleScript?

在网上找不到解决方法!这些代码无效!

tell application "Reminders"
    get count (reminders whose due date is (current date))
end tell

谢谢!

reminderdue date 可能永远不会匹配,因为 due date 表示为例如date "Wednesday, December 4, 2019 at 5:00:00 PM"(current date) 将表示为例如date "Wednesday, December 4, 2019 at 11:03:13 AM",所以除非这是 运行 date "Wednesday, December 4, 2019 at 5:00:00 PM",你的 get count ... 不匹配。

我会定位 (current date)date string,例如"Wednesday, December 4, 2019",但是 Reminders 不理解 date string of due date,即使 due date 表示为 日期对象 .

因此,获得 count 的一种方法是对每个 reminderdue date 进行 list,然后评估 date string每个针对 date string of (current date),使用以下 example AppleScript code:

tell application "Reminders"
    set ddList to the due date of every reminder
end tell

set ds to the date string of (current date)

set c to 0
repeat with d in ddList
    if d does not contain missing value then
        if date string of d contains ds then
            set c to c + 1
        end if
    end if
end repeat

return c

注意:示例 AppleScript code 就是这样,不包含任何可能适当的 error 处理。用户有责任根据需要或需要添加任何 错误处理 。看看 try statement and error statement in the AppleScript Language Guide. See also, Working with Errors.