I am trying to select all the events of the current date in iCal. This script errors when I try to obtain the date string of the start date:
tell application "iCal"
tell calendar "Home"
set theEvent to the summary of every event whose (date string of start date) = (date string of (current date))
theEvent
end tell
end tell
set cd to date string of (current date)
tell application "iCal"
tell calendar "Home"
set theEvent to the summary of every event whose (date string of start date) = cd
theEvent
end tell
end tell
It’s always (even before Snow Leopard) recommended to keep Standard Additions commands (like current date) out of application tell blocks
The current date part works ; the iCal start date seems to create the error:
get summary of every event of calendar "Home" whose date string of start date = "Thursday, November 5, 2009"
--> error number -1700 from date string of start date to specifier
set cd to (current date)
tell application "iCal"
tell calendar "Home"
set theEvent to the summary of every event whose start date = cd
theEvent
end tell
end tell
That runs fine, but it only returns the event(s) at that very moment, to the second (here: whose start date = date “Thursday, November 5, 2009 4:43:49 PM”)!
Since I need a list of all the events of the day, I need to eliminate the time part of the full date, to cover the 24 hours of the day (or at least the remaining time until midnight of that date).
tell (current date) to set today to (it - (its time))
set tomorrow to today + days
tell application "iCal"
tell calendar "Home"
set theEvent to the summary of every event whose (start date ≥ today) and (start date < tomorrow)
theEvent
end tell
end tell
Edit: nonsense, this is sufficient
tell (current date) to set today to (it - (its time))
tell application "iCal"
tell calendar "Home"
set theEvent to the summary of every event whose (start date ≥ today)
theEvent
end tell
end tell
Caution: The edited script does not return the correct data: since there is no upper limit, it returns all the events after the date! The first version of the script does work and returns the all the events of the current date