Cynical Calendars - Trigger Indigo activity from iCal events

Posted on
Sun Aug 12, 2012 4:50 pm
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Cynical Calendars - Trigger Indigo activity from iCal events

This is an experimental plugin - it seems to be working fine, but I'm not sure how useful it is to you in its current form.

Cynical Calendars lets you create Indigo triggers that fire when particular types of iCal events happen - when they start or end. Every time you create such an event trigger, you can specify conditions for matching iCal events - a calendar, regular expressions for the title, notes, and location, and some filters on the event's nature. Any time a calendar event starts or ends that matches all these criteria, your Indigo event fires and lets you do whatever you feel like doing.

Cynical Calendars hooks directly into your Macintosh's Calendar Store. It can monitor anything that you've told your Mac's calendar about: local calendars, iCloud calendars, shared and imported calendars, arbitrary CalDAV calendars, even the silly little birthday calendar - they're all yours to use with this plugin. And yes, if you add a calendar event on your iPhone or iPad, Cynical Calendar will pick up on that and (if it matches) execute your event triggers.

There's an innocent little checkbox that tells Cynical Calendars to take the Notes field in any matching calendar event and execute it as Python code when the trigger fires. Yes, this does exactly what it sounds like - except that the Python code is actually running in the context of a plugin formula, so that you can "pick up" Indigo constructs like variables directly by name. See the separate thread on plugin formulas for more information.

What would you use this for? I'm... not sure. That is why I'm putting it out for you in this rudimentary form - have a try and see what sense you can make of it. You could use it to program Indigo from iCal (or any calendar program on your Mac or iOS device). Or you could keep all the programming in Indigo and use the calendar as a time code generator. Or you could simply use it to integrate your house into your well-arranged calendar schedule. Or you could surprise me with something altogether more interesting than those...

Anyways, let me know if you run into any trouble, or if you find a way to make this plugin be useful to you and your house.

More information and download from here: http://www.cynic.org/indigo/plugins/online/ical.html

Cheers
-- perry

Posted on
Tue Aug 14, 2012 2:50 pm
brianmaas offline
Posts: 23
Joined: Oct 05, 2010

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Thanks for the plugin. I've installed it and am trying to get it to work with my setup. So far i haven't been able to get it to see any events. I've tried doing specific title searches and just leaving it blank to trigger something if any event is added. I turned on debugging and see what looks like initialization logs but i never see any log data about calendar events.

Code: Select all
 
Cynical Calendars               mapping event "look for alert" 1837522217(calchange)
Cynical Calendars               look for alert starting
Cynical Calendars               mapping event "look for sprinklers" 1766230573(calevent)
Cynical Calendars               look for sprinklers starting
Cynical Calendars               plugin starting asyn operation


Could it have something to do with my hardware and OS? I'm still running a G5 processor on a MacMini with OS 10.5.8. The plugin does see the calendars I have because it lists them in the dropdown.

I've always wanted this functionality to view ical, especially mobileme shared calendars. I wanted it to look for any events during the next 24 hours with the word "party" in the title. Then that day i wouldn't water the grass so it wouldn't be damp when the kids played on it. The plugin as is can't get me there yet but it's close. It would also be nice to do alerts a certain time before an event. To solve both of those you could add a field on the trigger for "minutes before". Instead of firing when the event starts it could fire that many minutes before the event starts. That way a user could always be reminded of a saved search query like "early dismissal" but fire off 15 minutes before that. Also my sprinkler problem would work with 1440 minutes which is 24 hours. If it sees a party scheduled i can have indigo set a variable to not start the sprinklers for 24 hours after it is set.

I think this would be an important feature for the plugin because these calendars aren't dedicated indigo calendars. In my case they are my family's shared calendar. I wouldn't want extra events in there for automation. I just want indigo to be able to work with what i already have.

Posted on
Tue Aug 14, 2012 3:18 pm
brianmaas offline
Posts: 23
Joined: Oct 05, 2010

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

I take it back. My first trigger worked! It might have been restarting the server that did the trick.

Posted on
Tue Aug 14, 2012 4:05 pm
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

I take it back. My first trigger worked! It might have been restarting the server that did the trick.


I'm glad. I admit I never tested this on Leopard (10.5), and while the Calendar Store API is supposed to work fine there, it's been a bit... difficult to work with at times.

Right now, this is a very minimal plug-in. The underlying code is perfectly capable of scanning through your entire calendar database (every last event instance in every calendar) - the problem is how to hook this capability up to Indigo in a way that makes it feel like it actually belongs there.

Cheers
-- perry

Posted on
Thu Oct 18, 2012 12:17 pm
macpro offline
User avatar
Posts: 765
Joined: Dec 29, 2005
Location: Third byte on the right

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Cool!

A while ago, I transformed my TV to be an Indigo client. Tonight I was thinking how it would be nice if I could get a message on my TV when an iCal event is about to happen. And now I find that all the building blocks are already available for Indigo.
I'll start some prototyping right now, but already have a request: is it possible to let this plugin respond to the alarms that can be set on any iCal event?
My iPad and iPhone show a message for instance 30 minutes before an appointment. I would like Indigo to be triggered at the same moment.
Last edited by macpro on Thu Oct 18, 2012 12:50 pm, edited 1 time in total.

Posted on
Thu Oct 18, 2012 12:31 pm
macpro offline
User avatar
Posts: 765
Joined: Dec 29, 2005
Location: Third byte on the right

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

I've got the plugin working, really easy.
But how can I use info from the iCal event that fires the Indigo trigger?

I would like to get the iCal event title and location so I can show them on my TV.

Posted on
Mon Jul 29, 2013 6:07 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Thought I'd experiment some with the plugin but when I attempt to setup a trigger I
get this in the event log:


Cynical Calendars Error Error in plugin execution UiGetValues2:

Traceback (most recent call last):
<type 'exceptions.TypeError'>: object of type 'NoneType' has no len()

Cynical Calendars Error in getIOMConfigUiXml:
File ".../Server Plugin/cyin/plug.py", line 303, in getIOMConfigUiXml
(cls, obj, dev) = self._startUi(type, id)
File ".../Server Plugin/cyin/plug.py", line 292, in _startUi
obj = iom.trigger(id, ui=self._ui)
File ".../Server Plugin/cyin/iom.py", line 98, in trigger
start_object(iotrig, iodev.pluginTypeId, ui=ui) # canonical create-and-optional-start
NameError: global name 'iodev' is not defined

Error (client) getXmlFromPlugin() caught exception: empty XML string returned
Error (client) dialogForEventId() caught exception: NSInvalidArgumentException -- *** -[NSCFDictionary initWithObjects:forKeys:count:]: attempt to insert nil value at objects[0] (key: string)
Cynical Calendars Error in getIOMConfigUiValues:
File ".../Server Plugin/cyin/plug.py", line 309, in getIOMConfigUiValues
(cls, obj, dev) = self._startUi(type, id)
File ".../Server Plugin/cyin/plug.py", line 292, in _startUi
obj = iom.trigger(id, ui=self._ui)
File ".../Server Plugin/cyin/iom.py", line 98, in trigger
start_object(iotrig, iodev.pluginTypeId, ui=ui) # canonical create-and-optional-start
NameError: global name 'iodev' is not defined

Running OS 10.5.8 and Indigo 6b11

Thank,

Carl

Posted on
Mon Jul 29, 2013 7:33 pm
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

I could see using this plugin. We have daycare and at times it changes from time to time. I control my child's occupancy between home and away with a schedule in indigo... but as I said, this changes. Using this plugin would allow me to drive her occupancy based on her calendar... this would be great and move a lot of logic out of indigo and at the same time making it more accurate.

Posted on
Mon Jul 29, 2013 11:20 pm
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Ckeyes888: Sorry about that. That was an old-ish bug in the support harness that went unfixed for way too long. (Well, actually it got fixed long ago. I just forgot to update the plugin.) Get 1.5.1 and it should be better.

Dewster35: Give it a spin and let me know what you think it missing. One "dark horse" feature is that Cynical Calendar has no trouble responding to calendar events you enter on your iOS device. It pretty much doesn't care how an event got into your calendar...

Oh, and a shout-out to 'macpro' for reporting a bug that's also fixed in this release.

Generally speaking, this plugin is currently minimalistic, and it's been a low priority of mine - it's one of the few that I don't actively use right now, and it shows. Still, it has its uses, and I'm listening to your suggestions. (I may be slow to implement them... :-))

Those of you who want your calendar events to have access to the various fields of the event, here's a hint: If you check the Execute event notes as a Python script checkbox for a calendar event, anything you enter into the Notes part of a calendar event will be, well, executed as Python code. This is cool because inside that script, you have a variable called event that is the calendar event that triggered the Indigo event, and it has a bunch of useful attributes. In particular, the title, location, and calendar can be directly accessed:
Code: Select all
log("Event", event.title, "at", event.location, "in", event.calendar.title, "type", event.type)

Depending on your needs, you can use Python code in the Notes to directly tell Indigo to do stuff, or set Indigo variables as needed to trigger further actions:
Code: Select all
indigo.variables.updateValue("CurrentTitle", event.title)

These days, I like this better than directly setting Indigo variables from plugin event triggers because that's inherently racy - I have no way to keep multiple events firing simultaneously from stomping on each other's variable settings.

Let me know if I need to elaborate on this...

Cheers
-- perry

Posted on
Tue Jul 30, 2013 7:33 am
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Perry The Cynic wrote:
Dewster35: Give it a spin and let me know what you think it missing. One "dark horse" feature is that Cynical Calendar has no trouble responding to calendar events you enter on your iOS device. It pretty much doesn't care how an event got into your calendar...


Perry,
This works great! Simple... and that is how is should be. Two triggers... one for the event start and one for the event end. Thanks for the work Perry!

Posted on
Tue Jul 30, 2013 12:11 pm
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Is there some way to use wildcards with python "regular expressions"? I can think of another use for this, but it would require some wildcard uses like *meeting* where it looks at my work schedule and sees if I have a meeting.... however, the meeting names can be all over the map. If I have that flexibility, I can do some good stuff such as turn on a light outside my home office so my wife doesn't burst in while I'm in a meeting :)

Posted on
Tue Jul 30, 2013 1:43 pm
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Dewster35 wrote:
Is there some way to use wildcards with python "regular expressions"? I can think of another use for this, but it would require some wildcard uses like *meeting* where it looks at my work schedule and sees if I have a meeting.... however, the meeting names can be all over the map. If I have that flexibility, I can do some good stuff such as turn on a light outside my home office so my wife doesn't burst in while I'm in a meeting :)

Yes. In Cynical Calendar, matches by default are "anywhere inside", so a pattern of Meeting would match Home Association Meeting or Meeting Reminder (but not, by default, meeting since it's case sensitive - start your match with (?i) to make it case insensitive).

Take a look at http://docs.python.org/2/library/re.html for an introduction and detailed documentation. Or just google "PCRE" (Perl Compatible Regular Expression") for help.

Cheers
-- perry

Posted on
Tue Jul 30, 2013 1:50 pm
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Perry The Cynic wrote:
Yes. In Cynical Calendar, matches by default are "anywhere inside", so a pattern of Meeting would match Home Association Meeting or Meeting Reminder (but not, by default, meeting since it's case sensitive - start your match with (?i) to make it case insensitive).

Take a look at http://docs.python.org/2/library/re.html for an introduction and detailed documentation. Or just google "PCRE" (Perl Compatible Regular Expression") for help.

Cheers
-- perry


Thanks Perry... had visited that from the link on your website but it looked a little daunting ;)

Posted on
Tue Jul 30, 2013 2:03 pm
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Small spelling error. .... "Existing" Event for the attached image for Configure Event Change Dialog Box.

Perhaps I'm thinking too narrow mindedly, but wouldn't you want the event end and event deleted to have the same function? I get that ical probably calls out these two things differently, but I would think... assume :/ that most people have an event start something and an event switch something back? And they would want the trigger to change it back to be the same whether it ended naturally or if it ended by someone deleting it? Same thing goes for the start of an event or a new event that is occurring now.

Even if the trigger isn't starting or ending something, I think the two ical signals are essentially same and can't really think of a use where you would want one and not the other.

Again, maybe I'm being short sighted, but it seems cumbersome to have to have two triggers, one for an event deletion and one for an event ending naturally.
Attachments
Untitled.tiff
Untitled.tiff (50.77 KiB) Viewed 5180 times

Posted on
Tue Jul 30, 2013 4:27 pm
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: Cynical Calendars - Trigger Indigo activity from iCal ev

Dewster35 wrote:
Perhaps I'm thinking too narrow mindedly, but wouldn't you want the event end and event deleted to have the same function? I get that ical probably calls out these two things differently, but I would think... assume :/ that most people have an event start something and an event switch something back? And they would want the trigger to change it back to be the same whether it ended naturally or if it ended by someone deleting it? Same thing goes for the start of an event or a new event that is occurring now.

Roughly, Calendar Event events report time passing, while Calendar Change events report editing of the calendar itself. They are very different things. Consider the case of a repeating event. Ending it means the current instance has ended. Deleting it means they're all disappearing and the event will never happen again.

I agree that deletion of an active event should signal termination as if a currently active event had ended. I can do that fairly straight-forwardly. But that's not the whole answer. What should happen if the calendar event gets edited and moved away from now? What should happen if a new calendar event is created straddling the current time? For that matter, what should happen for multiple overlapping calendar events that happen to both match your criterion? Some responsibility, in general, will have to lie with the user... which is why they are two different events, one specifically reporting editing activity.

Cheers
-- perry

Who is online

Users browsing this forum: No registered users and 11 guests