Now, I tried to add a location to an event on OS X 10.10.5.
This script seems to be failed to make a geofence alarm.
Adding location to an event is very useful for every scripters.
Can anybody help me? This is not an urgent issue :-).
-- Created 2014-12-08 by Shane Stanley
-- Modified 2015-09-24 by Takaaki Naganoya
--Reference:
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "EventKit"
--Fetch an event to add geofence alarm
tell application "Reminders"
tell account "iCloud"
tell list "Home" --Use "Home" in English environment or your favorite one
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
--> "868467FD-1F90-47EF-A9B1-A39334341D41"
setLocationToEnterForReminderID(35.745769, 139.675565, "Game City, Itabashi Branch", theID)
on setLocationToEnterForReminderID(aLatitude, aLongitude, aTitle, theID)
-- Get event store; 1 means reminders
set eventStore to current application's EKEventStore's alloc()'s initWithAccessToEntityTypes:2 --Deprecated in OS X 10.9 ?
(* Enums: { EKEntityTypeEvent:0, EKEntityTypeReminder:1} But this should be 2 or greater *)
-- Get the reminder
set theReminder to eventStore's calendarItemWithIdentifier:theID
--> (EKReminder) EKReminder <0x6e4a00>, localUID:868467FD-1F90-47EF-A9B1-A39334341D41, sharedUID:9999X999-X9X9-99XX-XXX9-X99X9XX9XXXX, cachedHasAttendee:0, cachedHasAlarm:1, cachedIsCalendarOwnerInvitedAttendee:0, cachedIsCurrentUserInvitedAttendee:0, calendarItemPermissionNumber:0, cachedHasLocationAlarm:0
--Create the geofence alarm
set enterAlarm to current application's EKAlarm's alloc()'s init()
enterAlarm's setProximity:1 -- EKAlarmProximityEnter
(* Enums: { EKAlarmProximityNone:0, EKAlarmProximityEnter:1, EKAlarmProximityLeave:2 }*)
--> (EKAlarm) EKAlarm <0x6b6920>, isSnoozed:0, isDefault:0
set structLoc to current application's EKStructuredLocation's locationWithTitle:aTitle
--> (EKStructuredLocation) EKStructuredLocation <0x8994b0> {title = Game City, Itabashi Branch; address = (null); geo = (null); abID = (null); radius = (null); routeType = (null)}
set aLoc to current application's CLLocation's alloc()'s initWithLatitude:aLatitude longitude:aLongitude
--> (CLLocation) <+35.74576900,+139.67556500> +/- 0.00m (speed -1.00 mps / course -1.00) @ 2015/09/24 11時14分37秒 日本標準時
structLoc's setGeoLocation:aLoc
-- Set radius by meters
structLoc's setRadius:200.0 --by meters
enterAlarm's setStructuredLocation:structLoc
--> (EKAlarm) EKAlarm <0x2ac480>, isSnoozed:0, isDefault:0
theReminder's addAlarm:enterAlarm --Error did not cause if I commented out this line
--> (* (EKReminder) EKReminder <0x2f1380>, localUID:868467FD-1F90-47EF-A9B1-A39334341D41, sharedUID:1714A240-E3E6-48FD-BCE4-D50E4FE9FCFF, cachedHasAttendee:0, cachedHasAlarm:0, cachedIsCalendarOwnerInvitedAttendee:0, cachedIsCurrentUserInvitedAttendee:0, calendarItemPermissionNumber:0, cachedHasLocationAlarm:0 *)
set aRes to eventStore's saveReminder:theReminder commit:true |error|:(missing value)
--> error number -10000 *** setObjectForKey: key cannot be nil
return aRes as boolean
end setLocationToEnterForReminderID