• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: due dates, reminders, & AppleScript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: due dates, reminders, & AppleScript


  • Subject: Re: due dates, reminders, & AppleScript
  • From: Shane Stanley <email@hidden>
  • Date: Sat, 08 Mar 2014 10:38:24 +1100

On 8 Mar 2014, at 4:09 am, 2551 <email@hidden> wrote:

 I still can’t figure out the ASObjC syntax for setting an Objective-C @property in AppleScript. I had a few unsuccessful attempts at it, but I won’t embarass myself by posting them. 

If the property is dueDateComponents, you use setDueDateComponents:newValue.

Suffice to say, if anyone can offer pointers, thoughts, objections, or just plain rumours, on how one might set the due date on an existing reminder (not a new one, mind you!), they’d be much appreciated (Oh, and do remind me to set a reminder not to try scripting Reminders again). 

EventKit is not for the faint-hearted. Nevertheless, this probably does what you want, using normal AS to get the ID:

use framework "Foundation"
use framework "EventKit"

on setDueDate:ASDate forReminderID:theID
set theNSDate to my makeNSDateFrom:ASDate -- convert date to Cocoa using handler
set theCalendar to current application's NSCalendar's currentCalendar() -- get calendar
set theComponents to theCalendar's componentsInTimeZone:(current application's NSTimeZone's localTimeZone()) fromDate:theNSDate -- get date components of date
set eventStore to current application's EKEventStore's alloc()'s initWithAccessToEntityTypes:1 -- get event store; 1 means reminders
set theReminder to eventStore's calendarItemWithIdentifier:theID -- get the reminder
theReminder's setDueDateComponents:theComponents -- set due date
eventStore's saveReminder:theReminder commit:true |error|:(missing value) -- save
end setDueDate:forReminderID:

on makeNSDateFrom:theASDate
set {theYear, theMonth, theDay, theSeconds} to theASDate's {year, month, day, time}
if theYear < 0 then
set theYear to -theYear
set theEra to 0
else
set theEra to 1
end if
set theCalendar to current application's NSCalendar's currentCalendar()
set newDate to theCalendar's dateWithEra:theEra |year|:theYear |month|:(theMonth as integer) ¬
|day|:theDay hour:0 minute:0 |second|:theSeconds nanosecond:0
return newDate
end makeNSDateFrom:

Called by:

use theLib : script "<name of script>" 
use scripting additions

tell application "Reminders" to set theID to id of reminder 1
set theID to text 20 thru -1 of theID -- strip to just id
theLib's setDueDate:((current date) + (2 * days)) forReminderID:theID


-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Scriptable multi-clipboard utility?
  • Next by Date: Re: Scriptable multi-clipboard utility?
  • Previous by thread: Re: Scriptable multi-clipboard utility?
  • Next by thread: Re: due dates, reminders, & AppleScript
  • Index(es):
    • Date
    • Thread