In my calendar “Work” I have 3 repeating events (all called “Working”) 1 on Wednesdays, 1 Friday, 1 Sunday
I want the code to output the date and start time of the next event in the calendar, so as today is Thursday, it would output " 24th May 2013 HH:MM:SS" as the next event is the Friday one.
However, the days and times of these events are subject to change, and extra events might be added, for example one week I could work my 3 standard days, but then work extra on two different days, so the output would have to reflect that
It can be a bit confusing terminologywise. An event which repeats is just one event. It has one start date (its first expression in the calendar display) and that’s what Calendar returns to the script. Repeats are calculated on the fly by Calendar and displayed in the appropriate places. A script to get the expression dates of the repeats has to do the same thing ” calculate them according to rules which can be very simple or very complex, depending on how the repeat sequence is specified and on whether any of the repeat instances have been altered, moved to different times, or deleted in Calendar’s GUI. That’s what the script in the other thread does.
When you talk about ‘next “Work” event’, I need to be sure whether you actually mean ‘next “Work” event’ or ‘next expression of a “Work” event.’ I think you mean the latter, in which case the script in the other thread, run with the either of the code samples in post #11 above, should produce the results you want.
Hi, i think i mean the next expression of a work event as the event itself started in march 2012.
I’ve included a screenshot of my calendar so you can hopefully visualise it more. Each of these events it a recurred from march 2012 when it was first set
i hope this allows you to understand what i mean. and a final run of the code would be great as i got lost to where were up to so have all manner of code mixed together
many thanks
James
EDIT: yes i’m at work at the min, this is beign run on my mac at home though
-- The script at <http://macscripter.net/viewtopic.php?pid=114724#p114724> goes here.
-- Replace the last six, commented-out lines with the following:
tell application "Calendar" to set {allSummaries, allEventUIDs} to {summary, uid} of (every event of calendar "Work")
set checkDate to (current date)
set nextIterationDate to missing value
repeat with i from 1 to (count allSummaries)
if (item i of allSummaries is "Working") then
set thisIteration to (getNextRecurrence from checkDate for (item i of allEventUIDs) without straddle)
if ((thisIteration is not missing value) and ((nextIterationDate is missing value) or (thisIteration's |start date| comes before nextIterationDate))) then set nextIterationDate to thisIteration's |start date|
end if
end repeat
return nextIterationDate -- Returns an AppleScript date object.
The script assumes that the target calendar is stored on the startup volume in the normal location for the version of iCal/Calendar used. If not, it won’t work.
Your Calendar looks slightly different from mine. Is it the Lion version?
Many thanks, ill try this when I get home and let you know if it works
That version of the calendar looks different because it is the online iCloud.com version as I don’t have access to my Mac at home while at work I’m running ML at home though