Calendars App Get Start Date StefanK and Nigal Garvey

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! :frowning:

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?

Sorry again for deleting the previous thread

James

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.

Here’s the link to the script thread in case you’ve mislaid it: http://macscripter.net/viewtopic.php?pid=114724#p114724.

Hi

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?

Hi.

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

Hi,
Yes I had multiple repeating events called the same thing so that was the problem. I now have two options:

  1. Could you possible explain how I go about multiple repeating events with the same name?
  2. Add each event in seperatly so it will then work

Obviously option 1 is the preferred but I’m happy to settle with option 2

Many thanks again
James

Could it be that the calendar is not on your computer?

I’m not sure, both my calendar called “Calendar” and calendar called “Work” are stored in iCloud, so I’m not sure.

Hello.

Who is Nigal Garvey?

I believe you can go back and edit the headline for your post.

What?

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

However, code for many different repeating events inside the same calendar would be great!

Thanks again

Hi.

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. :slight_smile: McUsrII was alluding to the fact that you’ve spelt “Nigel” with an “a”.

If you click on AppleScript | Mac OS X, and read the heading of this thread, you’ll discover that you spelled Nigel’s name as NIgal. :slight_smile:

Not that I think he would care about it, because then he’d said something, but it is a heading afterall.

Okay,

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.

Apologies

Now I get it. The a! You’re funny McUsr. :smiley:

I didn’t mean to be funny.

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.

Don’t you think?

Hi JWalker1995,

Have you ever seen what the data for an event looks like?

Editted: I meant a Calendar ‘Event’.

kel

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

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.

Thanks

So, to be absolutely clear, do you want:

  1. The start time of the next ‘event’ element defined in the calendar? (The script in the other thread isn’t necessary for this.)
  2. The effective start time of the next appearance of an event or repeat thereof in the calendar display?