2012-08-07 94 views
0

我做了這個代碼,它應該解析給定的字符串用「/」分隔的消息,日期和時間,然後在Mountain Lion Reminders.app中做一個提醒。Appletscript日期屬性在Reminders.app

我的問題出現時,提醒似乎不喜歡我通過它的日期沒有很好的理由。

我收到此錯誤信息:

Invalid date and time date August 6 2012 6:00pm of list Reminders. 

這裏是我的代碼:

--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 

回答

1

以及有一個很好的理由。您正在告訴提醒應用程序將字符串格式的日期轉換爲日期對象。提醒不知道該怎麼做。 Applescript的確如此。所以,只需改變腳本的最後幾行,使applescript按如下所示進行操作即可。基本上,你永遠不應該讓應用程序去做一些不在它的applescript字典中的東西。

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 
+0

看來這是一個newb錯誤然後^^,感謝您的幫助 – jonathanwiesel 2012-08-07 15:15:03