Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript for integration of reminders and events?

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)

Posted on Nov 12, 2013 6:19 AM

Reply
Question marked as Best reply

Posted on Nov 12, 2013 12:16 PM

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

11 replies
Question marked as Best reply

Nov 12, 2013 12:16 PM in response to BeautifulBear

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

Nov 13, 2013 5:59 AM in response to John Maisey

Thank you SO MUCH! This really helped me to start experimenting back and forth. I actually managed to extend the script alot from your excellent starting point.


But, I soon realized I actually wanted it to work the other way around! *darn* e.g a script that would create a reminder for every new event...


Ive tried to create the solution myself;


tell application "Calendar"

tell calendar "Important Icloud"

set today to (current date)

set this_year to year of today

set this_month to month of today

set this_day to day of today


repeat with c in every event

set d to start date of c

set the_year to year of d

set the_month to month of d

set the_day to day of d

if (the_year = this_year) and (the_month = this_month) and (the_day = this_day) then

show c

end if

end repeat

end tell

end tell

tell application "Reminders"

set newremin to makenewreminder

set name of newremin to reminTitle

end tell


Not only doesnt this work, its alot of unnessesary code.


Any chance of mercy? 🙂

Nov 13, 2013 11:32 AM in response to BeautifulBear

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

Nov 14, 2013 6:37 AM in response to John Maisey

After a sligth change of plans Im so close to what I want. Instead of reminders Im going with things and the script now looks like this;


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 datetodaysDate)

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


end repeat

end repeat


end tell

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


This works great but has one problem. Only one todo is created despite all of the relevant info from the calendar i gathered. It probably has something to do with a missing "repeat with.." in the "tell things" part of the script. I tried to add a "repeat with..." command but so far I only managed to make the same single todo duplicate itself, rather than populate the list with todos based on all gathered events.


The goal is to get all future (or just all) events from specific calendar into things where the different info of the event (notes etc) translates into things´s notes and so on.


Im close, but I would never hav gotten this far without your help! Thanks!

Nov 14, 2013 9:58 AM in response to BeautifulBear

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

Nov 20, 2013 6:12 AM in response to John Maisey

I very thankful for all your help but I ahve yet another question which is driving me crazy! (And you seem to know this like back of your hand)


Another script im working on:



tell application "Reminders"

repeat with i from 1 to (count of every reminder of list "x")

set theReminder to (the first reminder of list "x" whose completed = false)

set reminderName to the name of theReminder


if due date of theReminderexists then deletetheReminder

end repeat


end tell


tell application "Calendar"



repeat with c in calendar "x"

set theEvents to (every event of c)

repeat with current_event in theEvents

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 "x"

if myNote is missing value then


makenewreminderat the end of reminderswith properties {name:myTitle, due date:myDate}

else


makenewreminderat the end of reminderswith properties {name:myTitle, due date:myDate, body:myNote}

end if

end tell

end tell


end repeat

end repeat


end tell


This script works just the way I want it to! Problem is, when I change the target calendar&reminder from "x" to "y" (just another set of calendar/reminder list) IT DOESNT WORK!! How can it work perfectly for on set of calendar/reminder lists but fail in others using the exact same script!? (Besides from the specified target lists, that is)


WHY?? Can you point me in the right direction?

Nov 20, 2013 10:33 AM in response to BeautifulBear

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

Applescript for integration of reminders and events?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.