• 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: Takaaki Naganoya <email@hidden>
  • Date: Mon, 08 Dec 2014 17:57:39 +0900

This script is great! But makes error -1708 in OS X 10.10.1 environment.
Something wrong with me?

<AppleScript>
-- Created 2014-03-08 by Shane Stanley
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "ASObjCExtras"
use framework "EventKit"


tell application "Reminders"
	tell account "iCloud"
		tell list "ホーム" --This means "Home" in Japanese Environment
			set theID to id of (last reminder whose completed is false)
		end tell
	end tell
end tell

set theID to text 20 thru -1 of theID
--> "x-apple-reminder://B63F627B-A177-4CA7-9811-2AEB4875B407"

setDueDate_forReminderID_(((current date) + (2 * days)), theID)



on setDueDate:ASDate forReminderID:theID

	-- convert date to Cocoa using handler
	set theNSDate to my makeNSDateFrom:ASDate

	-- get calendar
	set theCalendar to current application's NSCalendar's currentCalendar()

	-- get date components of date
	set theComponents to theCalendar's componentsInTimeZone:(current application's NSTimeZone's localTimeZone()) fromDate:theNSDate

	-- get event store; 1 means reminders
	set eventStore to current application's EKEventStore's alloc()'s initWithAccessToEntityTypes:1

	-- get the reminder
	set theReminder to eventStore's calendarItemWithIdentifier:theID

	-- set due date --> error number -1708
	theReminder's setDueDateComponents:theComponents

	-- save
	eventStore's saveReminder:theReminder commit:true |error|:(missing value)

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:

</AppleScript>


> 2014/03/08 8:38、Shane Stanley <email@hidden> のメール:
>
> 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

--
Takaaki Naganoya
email@hidden
http://piyocast.com/as/




 _______________________________________________
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


  • Follow-Ups:
    • Re: due dates, reminders, & AppleScript
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: [SOLVED] building an AppleScript editor app
  • Next by Date: Re: building an AppleScript editor app
  • Previous by thread: Re: building an AppleScript editor app
  • Next by thread: Re: due dates, reminders, & AppleScript
  • Index(es):
    • Date
    • Thread