【问题标题】:applescript error "invalid date and time date"applescript错误“无效的日期和时间日期”
【发布时间】:2015-01-03 10:45:34
【问题描述】:

伙计们,

我是 AppleScript 新手。我想将许多事件添加到 iCal 日历。所有事件都应该是全天事件,因此它们没有开始时间或持续时间。我在文本文件中有日期,每行一个。但我只是将它们作为字符串复制到脚本中。这是我的代码(缩短了日期列表):

set input to "03.01.2015
16.01.2015
30.01.2015
13.02.2015
20.11.2015
04.12.2015
18.12.2015"

repeat with datum in paragraphs of input
    tell application "Calendar" to tell calendar "Müll"
        make new event with properties {start date:date datum, summary:"Gargabe", allday event:true}
    end tell
end repeat

我从 Apple 脚本编辑器得到的错误是

Invalid date and time date (item 1 of every paragraph of 03.01.2015
16.01.2015
30.01.2015
...

现在,我运行的是英文版 OS X,但我的语言环境设置为德国。 (很想发布相应首选项屏幕的屏幕截图,但在 stackoverflow 上没有足够的声誉。)

有人提示我这里出了什么问题吗? 提前非常感谢!

(顺便说一句,在 OS X 10.10.1 上运行。)

【问题讨论】:

  • 根据this related question,Applescript 期望看到的日期完全取决于您在 Macintosh 系统偏好设置中选择的区域或日期格式。 “16.01.2015”格式是否正确?
  • 是的,系统偏好设置显示 dd.mm.yyyy 是它可以理解的正确日期。

标签: applescript icalendar


【解决方案1】:

10.8.5

我更改了设置以匹配您的地区:

repeat with datum in paragraphs of input
    set datum to date (datum as string)
    tell application "Calendar" to tell calendar "Home"
        make new event at end with properties {summary:"Gargabe", start date:datum, end date:datum, allday event:true}
    end tell
end repeat

(注意我必须重命名我的日历) 如果我将日期函数放在日历中告诉它失败,那么它的工作之外......这对你有用吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-26
    • 1970-01-01
    • 2018-01-10
    • 2017-08-26
    • 1970-01-01
    • 2014-10-13
    • 2016-02-10
    • 1970-01-01
    相关资源
    最近更新 更多