1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Reminders.appのリマインダーとEventKitフレームワークのEKReminderクラスのインスタンスを変換するAppleScript

Posted at
  • EKReminder: Reminders.appのリマインダーをEKReminderクラスのインスタンスに変換
  • EKReminderArray: 複数のリマインダーに対応
    • 第3引数のsortDescriptorsでソート順を指定可能
  • reminderInReminders: EKReminderクラスのインスタンスをReminders.appのリマインダーに変換
  • reminderListInReminders: 複数のEKReminderクラスのインスタンスに対応
use scripting additions
use framework "EventKit"
use framework "Foundation"

set eventStore to current application's EKEventStore's alloc()'s initWithAccessToEntityTypes:(current application's EKEntityMaskReminder)
tell application "Reminders"
	set reminderItem to my EKReminder(eventStore, reminder 1)
	set reminderArray to my EKReminderArray(eventStore, id of reminders whose completed = false, {current application's NSSortDescriptor's sortDescriptorWithKey:"self.title" ascending:true})
end tell
my reminderInReminders(reminderItem)
my reminderListInReminders(reminderArray)

on EKReminder(eventStore, aReminder)
	--require framework: EventKit, Foundation
	return item 1 of my EKReminderArray(eventStore, {aReminder}, {})
end EKReminder

on EKReminderArray(eventStore, reminderList as list, sortDescriptors as list)
	--require framework: EventKit, Foundation
	set reminderArray to current application's NSMutableArray's arrayWithCapacity:(count reminderList)
	repeat with aReminder in reminderList
		tell application "Reminders"
			if class of aReminder = reminder then
				set reminderIdentifier to (current application's NSURL's URLWithString:(id of aReminder))'s |host|
			else if aReminder starts with "x-apple-reminder://" then
				set reminderIdentifier to (current application's NSURL's URLWithString:aReminder)'s |host|
			else
				set reminderIdentifier to aReminder as text
			end if
		end tell
		set reminder to (eventStore's calendarItemWithIdentifier:reminderIdentifier)
		(reminderArray's addObject:reminder)
	end repeat
	return reminderArray's sortedArrayUsingDescriptors:sortDescriptors
end EKReminderArray

on reminderInReminders(reminder)
	--require framework: EventKit, Foundation
	return item 1 of my reminderListInReminders({reminder})
end reminderInReminders

on reminderListInReminders(reminderArray as list)
	--require framework: EventKit, Foundation
	set reminderList to {}
	repeat with reminder in reminderArray
		set reminderID to ((current application's NSString's stringWithString:"x-apple-reminder://")'s stringByAppendingString:(reminder's calendarItemIdentifier)) as text
		tell application "Reminders"
			set end of reminderList to reminder id reminderID
		end tell
	end repeat
	return reminderList
end reminderListInReminders
  • 2016-08-31: EventKitフレームワークを使ってEKReminderハンドラ、EKReminderArrayハンドラを作成
  • 2016-09-27: reminderInRemindersハンドラ、reminderListInRemindersハンドラを作成
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?