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


More than 3 years have passed since last update.
  • AppleScriptではメモの中で添付ファイルの位置を取得できない
    • Evernoteではノート末尾にまとめている
  • 他の環境では添付ファイルを取得できないかもしれない
    • エラーになる場合は次の2行を削除
      • set mediaFolder to alias ((path to ...
      • set end of attachmentFiles to file 1 of ...
    • 添付ファイルが保存されているフォルダの存在をチェックするように変更
use scripting additions
use framework "Foundation"

set chooseList to {}
tell application "Notes"
    repeat with i from 1 to count notes
        set end of chooseList to name of note i & return & i
    end repeat
    set chooseResult to choose from list my sortList(chooseList) with title "Notes to Evernote" with multiple selections allowed
end tell
if chooseResult = false then
    error number -128
end if

    set mediaFolder to alias ((path to library folder from user domain as text) & "Group")
    set existsMediaFolder to true
on error number -43
    set existsMediaFolder to false
end try

set exportedNotes to {}
repeat with aResult in chooseResult

    tell application "Notes"
        set {body:noteHTML, name:noteTitle, creation date:creationDate, attachment:attachmentsOfNote} to note (paragraph 2 of aResult as integer)
    end tell

    set attachmentFiles to {}
    if existsMediaFolder then
        repeat with anAttachment in attachmentsOfNote
            tell application "Finder"
                set end of attachmentFiles to file 1 of (folder 1 of mediaFolder whose name of file 1 = name of anAttachment) as alias
            end tell
        end repeat
    end if

    tell application "Evernote"
        set end of exportedNotes to create note with html noteHTML title noteTitle created creationDate attachments attachmentFiles
    end tell
end repeat
return exportedNotes

on sortList(aList as list)
    --require framework: Foundation
    set array to current application's NSArray's arrayWithArray:aList
    set comparator to my appropriateComparatorToSort(array's firstObject())
    return (array's sortedArrayUsingSelector:comparator) as list
end sortList

on appropriateComparatorToSort(anObject)
    --require framework: Foundation
    if anObject  missing value and (anObject's respondsToSelector:"localizedCaseInsensitiveCompare:") then
        return "localizedCaseInsensitiveCompare:"
        return "compare:"
    end if
end appropriateComparatorToSort


  • 2016-01-15: 作成
  • 2016-01-15: 添付ファイルが保存されているフォルダの存在をチェックするように変更
  • 2016-01-15: エラー回避のためノート選択機能廃止
  • 2016-01-16: ノート選択方法を改善
  • 2016-02-20: sortListハンドラ更新
Why not register and get more from Qiita?
  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