Normal is Best.

高校教師&パパコーチ&元SEのブログ

Evernoteにほぼ日手帳風のノートを自動生成するApplescriptを作ってみた

色々なサイトを参考にして、Evernoteにほぼ日手帳風のノートを自動生成するApplescriptを作ってみた。
2度目のApplescript作りで、初めてのApplescriptエディタを使っての作業だったので3時間程度かかった。

流れとしては、作成開始日付を入力して、何日分作成するのか指定して、結果が表示されるだけ。
この設定だと、平日分しかノートを作成しないのと、ノートブック名やノート名が自分仕様となっている点に注意。

以下スクリプト

set nowDateNumber to do shell script "date '+%Y%m%d'"

display dialog "Evernoteに日付ノートを作成します。" & return & "開始する日付を入力してください。" default answer nowDateNumber
set noteStartDateNumber to text returned of the result

set noteStartDate to current date
set year of noteStartDate to characters 1 thru 4 of noteStartDateNumber as text
set month of noteStartDate to characters 5 thru 6 of noteStartDateNumber as text
set day of noteStartDate to characters 7 thru 8 of noteStartDateNumber as text

display dialog "開始日付:" & noteStartDate & return & "次に、何営業日分作成するか指定してください。" default answer 1

set noteCount to text returned of the result

--#Evernoteを起動し、開始日から作成日付を生成
tell application "Evernote"
set noteDate to noteStartDate
repeat noteCount times
--#土日の場合は平日まで進める
if weekday of noteDate as number = 1 then
set noteDate to noteDate + days
else if weekday of noteDate as number = 7 then
set noteDate to noteDate + 2 * days
end if

--#ノート名の作成 yyyyMMdd(weekday)_担任ノート
set noteDateY to year of noteDate
set noteDateM to text -2 thru -1 of ("0" & (month of noteDate as number)) as text
set noteDateD to text -2 thru -1 of ("0" & (day of noteDate)) as text
set noteDateW to item (weekday of noteDate as number) of {"日", "月", "火", "水", "木", "金", "土"}
set noteTitle to (noteDateY & noteDateM & noteDateD & "(" & noteDateW & ")_担任ノート") as text

--#ノート生成
set notebookName to notebook "102_担任ノート"
create note title noteTitle with text "Here is my new text note" notebook notebookName created noteDate
--#create note title noteTitle from file "/Users/hkawahara/Dropbox/01_Action/template.html" notebook notebookName created noteDate

--#日付のカウントアップ
set noteDate to noteDate + days
end repeat
end tell

--#日付を1日戻す
set noteDate to noteDate - days

--#完了メッセージの表示
display alert "Evernoteへの日付ノート作成が完了しました。" & return & noteStartDate & return & "〜" & noteDate

今後の課題としては、テンプレートファイルを読み込んでのノート自動作成機能を追加したい。
なんど試してもmissing valueとなって実行されないので、時間をおいて取り組み直してみようと思う。

Return Top