【问题标题】:Applescript date comparison gives unexpected resultApplescript 日期比较给出了意想不到的结果
【发布时间】:2014-11-06 00:02:53
【问题描述】:

我有以下适用于 Outlook 2011 的 Applescript(底部)。我正在尝试将超过四个月的收件箱消息移动到“在我的计算机上”文件夹(在我的应用程序计算机上)。

当我运行脚本时,这行似乎总是返回 true,因此它会归档每条消息:

        if time received of msg > (current date) - 4 * (4 * weeks) then

我在 11 月 5 日发布,而我收件箱中最早的邮件是 9 月 1 日,因此不应触发此 if 语句。

这是示例运行的事件日志:

tell application "Microsoft Outlook"
    activate
    get every message of inbox
    count every message of inbox
    current date
end tell
tell current application
    current date
end tell
tell application "Microsoft Outlook"
    get time received of item 1 of every message of inbox
    (*time received of item 1 of every message of inbox*)
    move item 1 of every message of inbox to on my computer
    current date
end tell
tell current application
    current date
end tell
tell application "Microsoft Outlook"
    get time received of item 2 of every message of inbox
    (*time received of item 2 of every message of inbox*)
    move item 2 of every message of inbox to on my computer
    current date
end tell
tell current application
    current date
end tell
tell application "Microsoft Outlook"
    get time received of item 3 of every message of inbox
    (*time received of item 3 of every message of inbox*)
    move item 3 of every message of inbox to on my computer

完整脚本:

tell application "Microsoft Outlook"
    activate
    if messages of inbox = {} then
        error "No messages."
        error -128
    end if
    repeat with msg in messages of inbox
        if time received of msg > (current date) - 4 * (4 * weeks) then
            move msg to on my computer
        end if
    end repeat
end tell

【问题讨论】:

    标签: applescript


    【解决方案1】:

    4 *(4 * 周)是从 11 月 5 日起 4 个月前,所以大约是 7 月 5 日。如果您的消息时间是 9 月 1 日,那么它肯定会触发它,因为 9 月 1 日大于 7 月 5 日。也许您打算使用小于(即

    【讨论】:

    • 当然,这是一个简单的逻辑错误。感谢第二双眼睛。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-19
    • 2017-01-05
    • 2021-10-14
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    相关资源
    最近更新 更多