首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Reminders.app中的Applescript date属性

Reminders.app中的Applescript date属性
EN

Stack Overflow用户
提问于 2012-08-07 12:05:18
回答 1查看 2.9K关注 0票数 0

我编写了这段代码,它应该解析由"/“分隔的带有消息、日期和时间的给定字符串,然后在Mountain Lion Reminders.app中生成一个提醒。

我的问题出现在提醒似乎不喜欢我无缘无故传递给它的日期时。

我收到这个错误消息:

代码语言:javascript
复制
Invalid date and time date August 6 2012 6:00pm of list Reminders.

下面是我的代码:

代码语言:javascript
复制
--explode © 2008 ljr (http://applescript.bratis-lover.net)
on explode(delimiter, input)
local delimiter, input, ASTID
set ASTID to AppleScript's text item delimiters
try
    set AppleScript's text item delimiters to delimiter
    set input to text items of input
    set AppleScript's text item delimiters to ASTID
    return input --> list on error eMsg number eNum
    set AppleScript's text item delimiters to ASTID
    error "Can't explode: " & eMsg number eNum
end try
end explode

--reminders © 2012 Jonathan Wiesel (http://github.com/jonathanwiesel)
set myList to explode("/", "visit my mom/today/6:00pm")
set theReminder to item 1 of myList
set queryDay to item 2 of myList
set theHour to item 3 of myList
set theYear to year of (current date)
if queryDay = "today" then
   set theDay to day of (current date) as string
   set theMonth to month of (current date)
   set theDate to theMonth & " " & theDay & " " & theYear
else if queryDay = "tomorrow" then
   set theDay to (day of ((current date) + (24 * 60 * 60)))
   if (day of (current date)) < (day of ((current date) + (24 * 60 * 60)))
        set theMonth to month of (current date)
    else
        set theMonth to (month of ((current date) + (30 * 24 * 60 * 60)))
    end if     
       if year of (current date) < year of ((current date) + (24 * 60 * 60)) then
    set theYear to (year of (current date)) + 1
    set theDate to theMonth & " " & theDay & " " & theYear & " "
   else
    set theYear to year of (current date)
    set theDate to theMonth & " " & theDay & " " & theYear & " "
   end if
else
   set theDate to queryDay
end if

set stringedDate to theDate as string
set stringedHour to theHour as string
set stringedAll to stringedDate & " " & stringedHour
tell application "Reminders"
tell list "Reminders"
    make new reminder with properties {name:theReminder, due date:date stringedAll}
end tell
end tell
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-07 22:48:19

好吧,这有一个很好的理由。您正在告诉提醒应用程序将字符串格式的日期转换为日期对象。提醒并不知道如何做到这一点。Applescript做到了。因此,只需更改脚本的最后几行,让applescript执行以下操作即可。基本上,您永远不应该告诉应用程序去做它的applescript字典中没有的事情。

代码语言:javascript
复制
set stringedAll to date (stringedDate & " " & stringedHour)
tell application "Reminders"
    tell list "Reminders"
        make new reminder with properties {name:theReminder, due date:stringedAll}
    end tell
end tell
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11839101

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档