If anyone could link members StefanK and Nigal Garvey that would be great?
Sorry but I mistakenly deleted the whole thread instead of a single post!
Basically, StefanK I got your program to work - with repeating events - but only in the standard calendar called âCalendarâ it wonât look at any other calendars, when i enter calendar name âWorkâ it just returns ââ so any help with this would be great?
I wondered what had happened! The board got petulant when I tried to post a reply! :lol:
There were three problems with my script: the name change from iCal to Calendar, an error where Iâd renamed a variable but not all instances of it, and a couple of new date bugs in Mountain Lion.
I think itâs fixed now. It returns a record of all the properties of the next repeat instance, so for your purpose, you might write:
tell application "Calendar" to set eventUID to uid of (first event of calendar "Work" whose summary is "Working")
set checkDate to (current date)
set repeatDate to |start date| of (getNextRecurrence from checkDate for eventUID without straddle)
If you then wanted the date of the repeat after that, youâd do something like:
set checkDate to repeatDate + 1
set repeatDate to |start date| of (getNextRecurrence from checkDate for eventUID without straddle)
The script itself isnât too slow, but it may take Calendar a long time to identify the event if there are a lot of different events in the calendar. There is a possibly faster way to do that if necessary.
Again with your code I got your program to work - with repeating events - but only in the standard calendar called âCalendarâ it wonât look at any other calendars, when i enter calendar name âWorkâ it just returns âMissing Valueâ so any help with this would be great?
âmissing valueâ from my script means that the event whose UID was passed to it has no iterations after the date which was passed. Iâll check it over again in the morning, but perhaps you could look to see if you have more than one âWorkingâ event in the calendar (as opposed to one âWorkingâ event with several repeats). If you have, it would be a matter of identifying the specific one you want to pass to the script.
Okay, after further trial and error I have found that your code does work with other calendars, it is just specifically that one calendar that throughs an error! So I have deleted the calendar and started again and it works
However, code for many different repeating events inside the same calendar would be great!
Your option 2 is more immediately easy to implement, although possibly taking slightly longer:
tell application "Calendar" to set eventUIDs to uid of (every event of calendar "Work" whose summary is "Working")
set checkDate to (current date)
set nextIterationDate to missing value
repeat with i from 1 to (count eventUIDs)
set thisIteration to (getNextRecurrence from checkDate for (item i of eventUIDs) 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 repeat
return nextIterationDate
If the calendar contains a lot of events, it could be faster to have Calendar simply dump all the summaries and UIDs to the script and let the script match the UIDs to the summaries:
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
Option 1 would depend on âWorkingâ event recurrences not overlapping. Youâd need to get the âWorkingâ events with the nearest start date before and the nearest after the check date and just run the script on those.
Donât worry about it. McUsrII was alluding to the fact that youâve spelt âNigelâ with an âaâ.
Basically, in the calendar âWorkâ there are multiple repeating events called âWorkingâ, they never overlap, I just want it to return the start time of the next event âWorkingâ. Sorry if these has been explained but Iâve lost where we are up to.
I generally doesnât care much about spelling of names, unless there is some danger of taking one person for the other, but it looks alot better, if names are spelled correctly in the headings of threads.
Sorry, maybe I didnât make it clear, I know it will return in the form 'DD MonthName YYYY HH:MM:SS" but I have my own code to strip it down to the parts I need, so the returned date can be in any format you guys like
Thanks
Edit: sorry yes, Iâm filtering by summary, and then returning the start date, in the form above^
First you need to parse the info. Then, you need to calculate when the next occurrence will happen relative to the current date. The parsing part is the hard part, its trying to know what the text means. You can look in your library and open one of the Calendar files. That ws another way to do it, but you needed to restart afterwards, I donât know if you still need to restart now.
Yeah, I have a working solution from StefanK using his command line code, I just need help on it so it reads multiple re-occurring events with the same summary.