ジャムスタ

just another mind Style

リマインダーから要素を選択し、それをまとめる[AppleScript][Reminders]

リマインダーの続き。

 

今回はリマインダーから要素を取り出してみる。

 

やりたいことは、リマインダーの中身を確認、それをリスト表示、そこからユーザーが選択。選択したものをEvernoteなりなんなりに送信、という流れ。

 

ともあれコードを。

 

リマインダーにある、リマインダーという名前のリストの中身を取り出している。

 

set theEntry to ""
set theList to {}
set theOutput to ""
tell application "Reminders"
    repeat with i from 1 to (count of every reminder of list "リマインダー")
        set theReminder to reminder i of list "リマインダー"
        set reminderName to the name of theReminder
        --完了している?
        if theReminder is not completed then
            --期限はあるか?
            if due date of theReminder exists then
                set duedate to due date of theReminder
                set theEntry to reminderName & return & duedate
            else
                set theEntry to reminderName
            end if
            set theList to theList & theEntry
        end if
    end repeat
end tell


set taskCat to (choose from list theList with multiple selections allowed) as list

repeat with i from 1 to (count of every item of taskCat)
    set theOutput to (theOutput & item i of theList as string) & return & "---" & return
end repeat

display dialog theOutput
   

最初にリマインダーの中身を取り出し、そのタスクが完了しているかどうかを判断。完了しているものを表示しても仕方がないので、これは必須。

 

その後、そのタスクに期限があるのかどうかの確認。もしあれば、タスクの名前とその期限をリストに追加。なければ、タスク名だけを追加。

 

これをリマインダーの各要素に対して行う。

 

完了していない要素だけを入れたリストを、choose from list theListで表示。複数選択を可能にしている。

 

あとは選択されたものを入れたリストから要素を取り出し、改行と区切り線を追加して、テキスト用の変数に入れる。それがtheOutput。

 

今回はダイアログで表示してあるが、このtheOutputを元にEvernoteでmake noteすれば、リマインダーから選んだものをEvernoteに送信、というようなことが可能になる。