View unanswered posts | View active topics It is currently Wed May 22, 2013 1:19 pm



Reply to topic  [ 20 posts ]  Go to page: 1, 2  Next
 Speak iCal events on demand 
Author Message

Joined: Nov 30, 2006
Posts: 10
Post Speak iCal events on demand
My goal is to have a daily "Good Morning" message played when triggered via a RemoteLinc or other suitable trigger. In part of this message I'd like to include the events for the current day for designated calendar(s) in iCal. Something along the lines of:

"Good morning. The weather for today is ..... Garbage pickup is today. The plumber is at 10am. " Then play a selected podcast or playlist.

The trouble I'm having is getting a list of iCal events for a given day. I've seen Applescript code to list events for a calendar, but if an event is recurring it doesn't show up except for the first day. Has anyone done something similar? Any experience getting events from iCal via Applescript or otherwise?

I could of course use an Applescript in iCal to trigger an announcement, but I want to trigger it selectively with Indigo instead. Once I have this implemented I could even see providing different announcements for different users, where each user has their own trigger.


Mon Feb 04, 2008 2:51 pm
Profile

Joined: Aug 03, 2005
Posts: 285
Location: Wausau, WI
Post 
Ooh, that sounds pretty wicked cool. I want that too!!!


Mon Feb 04, 2008 5:57 pm
Profile WWW

Joined: Nov 30, 2006
Posts: 10
Post 
Well so far I haven't found any easy solution currently available so I am looking at developing a Cocoa command-line app then scripting addition to allow access to the CalendarStore framework Leopard provides.
See: http://developer.apple.com/leopard/overview/calendarstore.html.

I looked at other things (perl libraries, etc.) that could parse an ICS file, but that seems more complex. Using CalendarStore will of course require Leopard, but I'm ok with that. So far I've got a proof of concept command-line app that outputs today's events for all calendars.

I've done some programming in school and project management at work, but I am far from an expert so this is a learning experience for me. I've never done any Mac or XCode development until now.

Initially I will expand my command line app, to simply output the event text that I need, I will then call this from an applescript. My end goal is to write a scripting addition that will allow a Applescript to read from the CalendarStore framework. This way anyone could use it and filter the events however they want and then end up with Applescript objects. If anyone out there has an expertise or examples, especially in the scripting addition area, it would be a great help.


Thu Feb 07, 2008 12:03 pm
Profile

Joined: May 06, 2008
Posts: 133
Post 
I'd be interested in this type of script also


Tue May 13, 2008 7:56 am
Profile

Joined: Feb 01, 2007
Posts: 127
Location: Haugesund, Norway
Post 
I made one like this in automator. Its not entirely finished, working on the weather report part. Does anyone know how to extract info from the weather widget using applescript ?

I need to pull todays temperature, state (sunny, cloudy, rainy) and maybe windstatus, if this is possible. I suspect accuweather has more variables to play with.

So far the automator workflow works perfectly in the editor, but Im having some issues getting it to run properly as a standalone application. I think its a bug in leopard causing this.


Sat May 31, 2008 7:08 am
Profile

Joined: May 06, 2008
Posts: 133
Post 
What I ended up doing was to have an "awake" button on the keypadlinc in my bedroom. When I hit that, the applescript will switch on the speakers in the master bath, announce date and time, then play the latest podcast from weather.com for the area I live in. Once done, it then plays my favorite iTunes Radio station.


Sat May 31, 2008 11:46 am
Profile

Joined: Feb 01, 2007
Posts: 127
Location: Haugesund, Norway
Post 
Yeah, cant wait to get insteon here in europe :)

I was thinking of activating this with a variable change. I usually get up sometime between 5 and 6 in the morning, so a variable change in that timeframe might trigger the action. Was thinking something similar. If my detector in the bathroom detects movement between the given time, It changes the variable and gives me to morning action on my bathroom speaker. I just need to buy Airfoil :)

My automator process does this for me now: Greets me a with a welcome, explains what it is about to do, scans my calendars, gives me todays events spoken, checks the rss feed from weather.com in my area and speaks my local current conditions. I dont have a window on my bathroom. so that suits me fine. Thanks for the tip on weather.com!

When the warranty on my coffe machine goes out, I will put a switch inside it so it can preheat the water for me. That way, I´ll be just a click away from a cup of coffe after being done in the bathroom!

Ah, I love home automation! ;)


Sun Jun 01, 2008 3:08 am
Profile

Joined: May 23, 2008
Posts: 26
Location: Florida
Post speak ical events with applescript?
Has anyone figured out how to speak your ical events with an applescript? I have figured out the weather, date time, number of emails, and play music, and got that into a wake up script, but don't have my calendar yet. Thanks!


Wed Dec 17, 2008 1:30 pm
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6659
Location: Austin, Texas
Post Re: speak ical events with applescript?
Briand9 wrote:Has anyone figured out how to speak your ical events with an applescript? I have figured out the weather, date time, number of emails, and play music, and got that into a wake up script, but don't have my calendar yet. Thanks!


In a round about way, I have it working here. First, I set an email reminder for all events that I want spoken reminders. Then, on my Indigo server machine, I have it scan emails on that account looking for subject that starts with "Alarm - ", which is what iCal emails look like. I have it trigger an external AppleScript that checks Mail for new messages, and reads the message.

Convoluted, yes, but iCal doesn't have a plug-in API (like Address Book) so you have to hack it a bit. I've toyed with creating a little app that would just open the calendar store that iCal uses and try to snarf upcoming events, but just haven't gotten to it. It would be Leopard-only since the calendar store API is only available on 10.5+.

_________________
Jay (Indigo Support)
Image


Wed Dec 17, 2008 7:41 pm
Profile WWW

Joined: Nov 30, 2006
Posts: 10
Post 
I love the convoluted email/iCal alarm solution. I tried building a CalenderStore-Applescript helper app but quickly got overwhelmed. I think the email method however convoluted is a much easier to implement and even somewhat elegant. I plan to implement it as soon as I have some spare time.


Thu Dec 18, 2008 9:33 am
Profile

Joined: Aug 03, 2005
Posts: 285
Location: Wausau, WI
Post 
The email idea is awesome. Should easily simplify getting it to work.

I sort of got it to read me messages through automator, but it was far from reliable.

_________________
Brian Jojade
HappyMac Digital Electronics
http://www.happymacshop.com


Fri Dec 19, 2008 2:15 pm
Profile WWW
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6659
Location: Austin, Texas
Post 
Well, you guys seem interested, so here's my script as it stands at the moment:


Code: Select all
property iCalAlarm : "iCal Alarm Group"
property shouldReadiCalAlarm : true

tell application "Mail"
   set loopCounter to 10
   repeat
      check for new mail
      set newMessageList to messages in mailbox "INBOX" of account "automatedemail" whose read status is false
      if (((count of items in newMessageList) > 0) or (loopCounter = 0)) then
         exit repeat
      end if
      set loopCounter to loopCounter - 1
      delay 5
   end repeat
   repeat with theMessage in newMessageList
      set theSubject to subject of theMessage
      if the first word of theSubject is "Alarm" then
         set theBody to (content of theMessage) as string
         set AppleScript's text item delimiters to ":"
         set theDate to my date (text items 1 through 2 of theBody as string)
         set theHours to ((hours of theDate) as number)
         if (theHours > 12) then
            set theHours to theHours - 12
            set amPm to "PM"
         else if (theHours = 12) then
            set amPm to "PM"
         else
            set amPm to "AM"
         end if
         set theMinutes to minutes of theDate
         if (theMinutes < 10) then
            set theMinutes to "0" & (theMinutes as string)
         else
            set theMinutes to (theMinutes as string)
         end if
         set theTime to ((theHours as string) & ":" & (theMinutes as string)) & " " & amPm
         set theSummary to my trim(text item 3 of theBody as string)
         set read status of theMessage to true
         tell application "IndigoServer"
            if (shouldReadiCalAlarm) then
               say ("Calendar Event Reminder: " & theSummary & " at " & theTime)
            end if
            if (action group iCalAlarm exists) then
               execute group iCalAlarm
            end if
            log theSummary & " at " & theTime using type "iCal Reminder"
         end tell
      end if
   end repeat
end tell

on trim(inString)
   set AppleScript's text item delimiters to ""
   repeat while (character 1 of inString = white space)
      set inString to (characters 2 through (length of inString)) of inString as string
   end repeat
   repeat while (character (length of inString) of inString = white space) or (character (length of inString) of inString = (ASCII character 10))
      set inString to ((characters 1 through ((length of inString) - 1)) of inString) as string
   end repeat
   return inString
end trim


The loop at the beginning is because sometimes Mail seems to be a little slow at picking up new mail - so, even though Indigo found a new message via POP, Mail may not see it yet, so I just put in a loop until it finds something or gives up after 10 times. Obviously, you'd want to change the name of the account.

Anyway, it probably has bugs and could use more cleanup, but maybe it'll save someone a bit of time.

_________________
Jay (Indigo Support)
Image


Fri Dec 19, 2008 2:54 pm
Profile WWW

Joined: Jan 08, 2009
Posts: 13
Post 
I started working on a script to announce the day's calendar events, and of course, ran into all of the same problems listed here in this thread with repeating events. After Googling around, I came across most of the information that I needed to make something work. However, since the only way to find all active repeating events is to search through and analyze every calendar event, the process takes much longer than I would prefer. So, what I'm attempting to do is kick off a job at around 2am that will do all of the hard work, and then save it off to disk. Then, when I kick off the "Daily Report", I'd like to read that data in and announce it. Where I'm getting stuck now is when I have my list of records (I'm using Automator):

Code: Select all
{event id "DE1BB360-D612-4E1E-8FDC-B642CBAB4F04" of calendar id "5B2861FF-D79D-4386-BFDF-433C2A21424D" of application "iCal", event id "0CA46138-057D-49CC-BB2B-8D8850C6DE19" of calendar id "5B2861FF-D79D-4386-BFDF-433C2A21424D" of application "iCal"}


I'd like to save this to disk just as it is. Then, I'd like to use Automator to read that file in and use it as the input to the next step to a Run AppleScript step to do the announcing. Make sense?

I'm stuck saving the data to disk as AppleScript code (and then, of course, reading it back in to use it as AppleScript data). This is my first attempt using Automator, and I only have a little bit of AppleScript experience. Does anybody know if what I'm attempting to do is possible? Can anybody help?


Sat Jan 10, 2009 12:57 pm
Profile WWW

Joined: Jul 22, 2008
Posts: 1
Post 
I have a set of scripts that get triggered after a morning wakeup call - it works sort of like this:

Indigo triggers a time action at 6am (when I get up) that launches airfoil and connects to speakers in my bedroom, it tells me it's 6am and time to wake up. It then disconnects from those speakers and initiates an ssh connection to my media server telling IT to connect to my bedroom speakers and start up itunes with a specific playlist. That plays for approx. 45 seconds before fading the itunes volume down and greeting me and reading me the daily weather report. The weather is obtained during the 45 second music intro using a weather script that pulls the weather report in for my zip code. After it reads me the weather it turns the volume on itunes back up. It also turns on one of the keypad buttons on my bedroom keypadlinc, so to shut it all down i just press that button on my way out the door. That same button can be used to trigger the same events at any time (generally whenever I'm taking a shower).

I'm working on modifying it to also pull in my calendar entries. Since I RARELY have repeating events that doesn't matter much to me - it's the one-time events like a doctors appointment that I always end up forgetting.


Tue Feb 03, 2009 11:37 pm
Profile

Joined: Aug 07, 2003
Posts: 9
Location: San Jose, CA
Post 
I'm getting in late on this discussion, but I have a script that I'll share. I'm running on Leopard 10.5 now, and it has been working reliably since the days of Tiger 10.4. I have Indigo trigger it multiple times a day (morning, noon and afternoon) to announce the day's events. If the start time of the event has past for the day, that event is no longer announced. All-day type events are announced each time.

A modified version of the script, called Announce Tomorrow's events runs in the evening. The only change needed for that script is:
set Now to current date + (1 * days) -- fake the date for tomorrow
(and change any text referencing "today" to "tomorrow")

I have other similar scripts which have been massaged to produce other iCal event announcers, including recurring events. Indigo triggers running of the scripts or they can be invoked anytime from the Indigo or iCal scripts menu.

Hope this is useful…
Doug Korns

--
property Debug : false

if not Debug then
--Normal
set Now to current date
else
--Testing
set D to "05/05/2008"
set Now to (date D) -- + 9 * hours
end if

set TodaysDate to date string of Now
set MidnightToday to date TodaysDate
set MidnightTomorrow to (date TodaysDate) + (1 * days)

tell application "iCal"
if Debug then
set AllCalendars to {calendar "Doug", calendar "Jeanne"} -- subset of all calendars
else
set AllCalendars to every calendar
end if

repeat with EachCalendar in AllCalendars
set CalendarName to name of EachCalendar

set TodaysEvents to (every event of EachCalendar ¬
whose (start date is greater than MidnightToday and ¬
end date is less than MidnightTomorrow) or ¬
(start date is MidnightToday and allday event is true))
repeat with EachEvent in TodaysEvents
if contents of EachEvent is not missing value then
set TheEvent to contents of EachEvent
set EventProperties to properties of TheEvent
set EventName to summary of EventProperties
set EventLocation to location of EventProperties
set EventDescription to description of EventProperties

if not (allday event of EventProperties) then
set EventTime to "at " & time string of start date of EventProperties
if start date of EventProperties comes before Now then
set EventStillToCome to false
else
set EventStillToCome to true
end if
else
set EventTime to ", All Day"
set EventStillToCome to true
end if

if EventStillToCome then
set EventAttendees to attendees of TheEvent
set AttendeeNames to ""
repeat with EachAttendee in EventAttendees
set AttendeeName to display name of EachAttendee
set AttendeeNames to AttendeeNames & " ," & AttendeeName
end repeat

--Start building message
set EventMsg to ""
set EventMsg to EventMsg & "From the " & CalendarName & " Calendar, "
set EventMsg to EventMsg & "Today " & EventTime & ", "
set EventMsg to EventMsg & "is the " & EventName
if EventLocation is not in {missing value, ""} then ¬
set EventMsg to EventMsg & ", at " & EventLocation
set EventMsg to EventMsg & ". "
if EventDescription is not in {missing value, ""} then ¬
set EventMsg to EventMsg & "The notes indicate: " & EventDescription & ". "
if EventAttendees is not {} then ¬
set EventMsg to EventMsg & "Expected attendees are " & AttendeeNames & ". "
say EventMsg
end if
end if
end repeat
end repeat
end tell
--


Tue Feb 24, 2009 4:17 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 20 posts ]  Go to page: 1, 2  Next

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.   Template designed by STSoftware.