Reminders.app(リマインダー)に新規リマインド項目を作成し、Geofenceを設定するAppleScriptです。
Reminders.appのAppleScript用語辞書にはGeofence作成機能は用意されていないため、Cocoaの機能を利用して追加しました。
Geofenceは、指定の緯度・経度のポイントから半径xxxメートルの円の中に入る場合に発生するアラーム(Enter Alarm)、脱出する場合に発生するアラーム(Leave Alarm)の2種類を設定できます。
Mac上のReminders.app上で登録したこのリマインド項目がiCloud経由でiPhoneにシンクロされ、iPhoneを持って当該期間中に指定場所に行って半径200メートルの円の中から出るとアラームが表示されることになります。
AppleScript名:Geofenceを付けつつReminder項目を追加 |
— Created 2014-12-08 by Shane Stanley — Modified 2015-09-24 by Takaaki Naganoya –Geofence Alarm — Modified 2015-09-24 by Shane Stanley –Fix the way to Create the geofence alarm — Modified 2015-09-24 by Takaaki Naganoya –change and test for El Capitan’s Enum bridging –Reference: –http://stackoverflow.com/questions/26903847/add-location-to-ekevent-ios-calendar –http://timhibbard.com/blog/2013/01/03/how-to-create-remove-and-manage-geofence-reminders-in-ios-programmatically-with-xcode/ use AppleScript version "2.5" use scripting additions use framework "Foundation" use framework "EventKit" property EKAlarm : a reference to current application’s EKAlarm property CLLocation : a reference to current application’s CLLocation property EKEventStore : a reference to current application’s EKEventStore property EKStructuredLocation : a reference to current application’s EKStructuredLocation property EKEntityMaskReminder : a reference to current application’s EKEntityMaskReminder property EKAlarmProximityEnter : a reference to current application’s EKAlarmProximityEnter property EKAlarmProximityLeave : a reference to current application’s EKAlarmProximityLeave –Start Date set dSt to "2018/06/01 00:00:00" set dateO1 to date dSt –End Date set dSt2 to "2018/08/01 00:00:00" set dateO2 to date dSt2 tell application "Reminders" if not (exists list "test") then make new list with properties {name:"test"} end if tell list "test" set aReminder to (make new reminder with properties {name:"Test1", body:"New Reminder", due date:dateO2, remind me date:dateO1, priority:9}) –priority 1:高、5:中、9:低、0:なし set anID to id of aReminder –> "x-apple-reminder://XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" end tell end tell set theID to text 20 thru -1 of anID my setLocationToLeaveForReminderID(35.745769, 139.675565, "Target Place", theID, 200) –指定場所に到着した時に発動するGeofence Alarmを指定のリマインダーに登録する。Geofence半径指定つき(単位:メートル) on setLocationToEnterForReminderID(aLatitude, aLongitude, aTitle, theID, aRangeByMeter) — Get event store set eventStore to EKEventStore’s alloc()’s initWithAccessToEntityTypes:(EKEntityMaskReminder) — Get the reminder set theReminder to eventStore’s calendarItemWithIdentifier:theID –Create the geofence alarm set enterAlarm to EKAlarm’s alarmWithRelativeOffset:0 enterAlarm’s setProximity:(EKAlarmProximityEnter) set structLoc to EKStructuredLocation’s locationWithTitle:aTitle set aLoc to CLLocation’s alloc()’s initWithLatitude:aLatitude longitude:aLongitude structLoc’s setGeoLocation:aLoc — Set radius by meters structLoc’s setRadius:aRangeByMeter enterAlarm’s setStructuredLocation:structLoc theReminder’s addAlarm:enterAlarm set aRes to eventStore’s saveReminder:theReminder commit:true |error|:(missing value) return aRes as boolean end setLocationToEnterForReminderID –指定場所を出発した時に発動するGeofence Alarmを指定のリマインダーに登録する。Geofence半径指定つき(単位:メートル) on setLocationToLeaveForReminderID(aLatitude, aLongitude, aTitle, theID, aRangeByMeter) — Get event store; 1 means reminders set eventStore to EKEventStore’s alloc()’s initWithAccessToEntityTypes:(EKEntityMaskReminder) — Get the reminder set theReminder to eventStore’s calendarItemWithIdentifier:theID –Create the geofence alarm set leaveAlarm to EKAlarm’s alarmWithRelativeOffset:0 leaveAlarm’s setProximity:(EKAlarmProximityLeave) set structLoc to EKStructuredLocation’s locationWithTitle:aTitle set aLoc to CLLocation’s alloc()’s initWithLatitude:aLatitude longitude:aLongitude structLoc’s setGeoLocation:aLoc — Set radius by meters structLoc’s setRadius:aRangeByMeter leaveAlarm’s setStructuredLocation:structLoc theReminder’s addAlarm:leaveAlarm set aRes to eventStore’s saveReminder:theReminder commit:true |error|:(missing value) return aRes as boolean end setLocationToLeaveForReminderID |