iCal "vacation days"

Posted on
Tue Oct 12, 2010 9:58 am
baadpuppy offline
User avatar
Posts: 16
Joined: Oct 01, 2010
Location: Virginia

iCal "vacation days"

I'm still new to Indigo, and just learning a lot of this stuff.

My primary justification for getting into Indigo and Insteon was to make it easier for me to get up on time for work, with the lights already being on. I've been refining this as I go along, and it's all still quite rough around the edges. As for other justifications... well, does it really need justifying? :o

Yesterday was a work holiday (columbus day). Having the lights come on at 6:45am when I didn't have to get up was a bit annoying, but prompted me to spend some time solving that problem today.

At work, our email system has a calendar component that supports CalDAV. I've subscribed to my CalDAV account from iCal on my Indigo server. In that calendar, we have a shared calendar just for office events. All the holidays are in there in the format of "Holiday: Columbus Day", and are listed as "all day" events. So, the data needed to make this work was available, and I just needed a simple way to interface that into Indigo. You could just as easily use a local calendar, or export a .ics from some system and import it into iCal, or whatnot.

I've set up a time/date action, to fire at 12:30am (midnight:30) every day called "Daily tasks" for doing daily housekeeping routines. Currently, it runs an external applescript, which talks to iCal, and sets the Indigo variable. That variable is used by other actions to make decisions. I don't have any other actions yet, but can easily add more.

Here's the script.

Code: Select all
set myDate to date string of (current date)
set theCalendar to "Holiday Events" -- the calendar you're checking
set holidayVariable to "workHoliday"

on setVariable(theVariable, theValue)
-- borrowed from http://www.perceptiveautomation.com/wiki/doku.php?id=applescript_snippit
   tell application "IndigoServer.app"
      if variable theVariable exists then
         set value of variable theVariable to theValue
      else
         make new variable with properties {name:theVariable, value:theValue}
      end if
   end tell
end setVariable

-- presume a day isn't a holiday by default
setVariable(holidayVariable, "false")

tell application "iCal"
   set theEvents to every event of calendar theCalendar
   repeat with thisEvent in theEvents
      if date string of (get start date of thisEvent) is equal to myDate then
         if allday event of thisEvent then
            if (summary of thisEvent) contains "Holiday" then
               -- this day must be a holiday
               tell me to setVariable(holidayVariable, "true")
            end if
         end if
      end if
   end repeat
end tell


Perhaps this might be of use to someone else.

My original version was using curl to set the variable. However, when I realized I could really *only* run this script on the Indigo server itself, I used the more elegant snippet from the wiki.

jim

Posted on
Tue Oct 12, 2010 10:21 am
jay (support) offline
Site Admin
User avatar
Posts: 18243
Joined: Mar 19, 2008
Location: Austin, Texas

Re: iCal "vacation days"

Awesome, thanks for the script. I'm sure others will find it useful.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Nov 17, 2010 2:17 am
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: iCal "vacation days"

Very handy indeed, Jim! Thanks for sharing!

Posted on
Sat Dec 04, 2010 12:41 am
macpro offline
User avatar
Posts: 765
Joined: Dec 29, 2005
Location: Third byte on the right

Re: iCal "vacation days"

Very easy to set up and works perfect. Thank you!

Posted on
Fri Dec 17, 2010 3:50 pm
macpro offline
User avatar
Posts: 765
Joined: Dec 29, 2005
Location: Third byte on the right

Re: iCal "vacation days"

Found a little bug. The script doesn't recognize repeating days.
For instance: I have an event that occurs every other friday.
In iCal a repeating all day event is present for those days, but the scripts sets the variable to false.
When I make a single all day event with the same name, the script recognizes the event without a problem.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests