Skip navigation

Applescript for integration of reminders and events?

871 Views 11 Replies Latest reply: Nov 20, 2013 11:54 PM by BeautifulBear RSS
BeautifulBear Level 1 Level 1 (0 points)
Currently Being Moderated
Nov 12, 2013 6:19 AM

Ive been looking high and low for a script that would automatically create an event for every new reminder. Lets say I add "purchase a mac" with a due date on nov 13 5pm, an event would be created "purchase a mac" on the corresponding calendar at 5pm on that date!

 

Anyone who knows of/can create and share such a solution?

OS X Mavericks (10.9)
  • John Maisey Level 5 Level 5 (6,870 points)

    Hi,

     

    This would do the basics of what you ask. However I would recommend some level of error checking (i.e. if the event has no due date, if the calendar does not exist in the Calendar application etc.). You would also need to run the script after each time you enter the item in Reminders.

     

     

    -- John Maisey --
    -- www.nhoj.co.uk --
    -- 12 Nov 2013 --
    tell application "Reminders"
              set myReminder to last item of reminders
              set myCal to (name of (container of myReminder)) -- name of list
              set myTitle to (name of myReminder)
              set myDate to (due date of myReminder)
    end tell
    tell application "Calendar"
      launch -- open Calendar app if not already running
      delay 0.2 -- due to Calendar not being responsive to Apple Events just after launch
              tell calendar myCal to make new event at the end of events with properties {summary:myTitle, start date:myDate}
    end tell
    

     

     

    Best wishes

    John M

  • John Maisey Level 5 Level 5 (6,870 points)

    Or this?

     

     

    -- John Maisey --
    -- www.nhoj.co.uk --
    -- 13 Nov 2013 --
    set myCalendarName to "Calendar Name" -- < change this name.
    tell application "Calendar"
              tell calendar myCalendarName
                        set myEvent to last item of events
              end tell
              set myTitle to summary of myEvent
              set myDate to start date of myEvent
    end tell
    tell application "Reminders"
              tell list myCalendarName to make new reminder at the end of reminders with properties {name:myTitle, due date:myDate}
    end tell
    
  • John Maisey Level 5 Level 5 (6,870 points)

    I'm glad it helped. The reason why you only have one todo is that after the by calendar repeat and the by event repeat the variables set only come from the last event of the last calendar.

     

    Put the 'tell app "Things"' block inside the loop. Doing this can sometimes cause a terminology clash between two app's scripting dictionaries. I cannot check for that in this case as I do not have Things installed. (you could also put it the code into a sub-routine http://www.macosxautomation.com/applescript/sbrt/ but I won't go into that)

     

    John M

     

     

    tell application "Calendar"
    
     set todaysDate to current date
     set time of todaysDate to 0
     repeat with c in calendar "Det"
      set theEvents to (every event of c whose start date ≥ todaysDate)
      repeat with current_event in theEvents
       set out to summary of current_event & ""
       set myDate to start date of current_event
       set myContext to location of current_event
       set myNote to description of current_event
              tell application "Things"
                          set newToDo to make new to do ¬
                with properties {name:out, due date:myDate, notes:myNote} ¬
                                    at beginning of project "Det"
                          set notes of newToDo to myNote
                          set due date of newToDo to myDate
                          set tag names of newToDo to myContext
              end tell 
      end repeat
     end repeat
    
    end tell
    
    
  • John Maisey Level 5 Level 5 (6,870 points)

    I'm glad it helped.

  • John Maisey Level 5 Level 5 (6,870 points)

    Hi,

     

    I'm not sure why it would work in one calendar and not another.  There are some possible issues and if you could let me know what you expect to be happening I amy be able to see better what is  not working.

     

    I will say there will be an issue in the reminders repeat when you start looping through the number of items then deleting some of the items you can get to a point where there are not enough items..  It is possible you will get to a point where there are no reminders uncompleted, so the variable 'theReminder' does not contain anything on that loop and the script will stop.  Do you use the variable 'reminderName' anywhere else? I'd sugget not using the 'count' but getting an array of the items and then looping through them with a reference to the item (if that makes any sense).

     

    Also I'm not sure what the line 'repeat with c in calendar "x"' is doing. I expect this is meant to be  'repeat with c in events of calendar "x"', but I'm not sure.

     

    Would something like this work for both calendars?

     

     

    set myListCalendarName to "x"
    
    tell application "Reminders"
              set theReminders to (reminders of list myListCalendarName whose (completed is false))
              repeat with thisReminder in theReminders
                        if due date of thisReminder exists then delete thisReminder
              end repeat
    end tell
    
    tell application "Calendar"
      
              repeat with current_event in (every event of calendar myListCalendarName)
                        set myTitle to summary of current_event
                        set myDate to start date of current_event
      
                        set myNote to description of current_event
                        tell application "Reminders"
                                  tell list myListCalendarName
                                            if myNote is missing value then
      make new reminder at the end of reminders with properties {name:myTitle, due date:myDate}
                                            else
      make new reminder at the end of reminders with properties {name:myTitle, due date:myDate, body:myNote}
                                            end if
                                  end tell
                        end tell
      
              end repeat
      
    end tell
    
    
    
    

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.