Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.
  • 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ブロックを削除
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away