LoginSignup
2
2

More than 5 years have passed since last update.

Evernoteのノートをプレーンテキストで取得するAppleScriptハンドラ

Last updated at Posted at 2016-01-03
  • AppleScriptから取得できるノート内容はHTMLまたはENMLのみ
    • 最も有用なプレーンテキストでの取得はサポートされていない
      • プレーンテキストからノート作成はできるのに
  • HTMLをプレーンテキストに変換するハンドラを作成
  • ついでにgrepを用いて必要な行だけ簡単に抽出できるように
    • 第2引数で正規表現を使って指定
    • 例:ノートの中で"abc"から始まる行だけ取得するには^abc
plainContentOfNoteInEvernote.scpt
tell application "Evernote"
    set {aNote} to selection
end tell
return my plainContentOfNoteInEvernote(aNote, "^abc")

on plainContentOfNoteInEvernote(aNote, pattern as text)
    --pattern: 正規表現、grepでマッチした行を返す(使わない場合はpatternを""に、空行のみを除く場合はpatternを"."に)
    try
        return do shell script "osascript -e 'tell application \"Evernote\" to return HTML content of note id \"" & id of aNote & "\" of notebook 1' | textutil -convert txt -stdin -inputencoding UTF-8 -stdout -format html -noload | grep " & quoted form of pattern
    on error number 1
        return ""
    end try
end plainContentOfNoteInEvernote

更新履歴

  • 2011-07-12: HTMLタグを取り除く形式で作成
  • 2011-11-18: textutilで変換するように変更
  • 2012-10-27: echoによるパイプからHTMLファイルを指定するように変更
  • 2013-02-24: grep追加
  • 2014-06-30: textutilのオプションにinputencodingformatを入れて文字化け防止
  • 2016-01-03: HTMLファイルの指定からosascriptによるパイプに変更
  • 2016-01-04: textutilのオプションにnoloadを追加して動作高速化
  • 2016-01-21: 必要ないtellブロックを削除
2
2
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
2
2