LoginSignup
2
2

More than 5 years have passed since last update.

Macのメモ(Notes)からEvernoteにエクスポートするAppleScript

Last updated at Posted at 2016-01-15
  • AppleScriptではメモの中で添付ファイルの位置を取得できない
    • Evernoteではノート末尾にまとめている
  • 他の環境では添付ファイルを取得できないかもしれない
    • エラーになる場合は次の2行を削除
      • set mediaFolder to alias ((path to ...
      • set end of attachmentFiles to file 1 of ...
    • 添付ファイルが保存されているフォルダの存在をチェックするように変更
Notes_to_Evernote.scpt
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
    activate
    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

--添付ファイルフォルダを取得
try
    set mediaFolder to alias ((path to library folder from user domain as text) & "Group Containers:group.com.apple.notes:Media:")
    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

    --Evernoteにノート作成
    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:"
    else
        return "compare:"
    end if
end appropriateComparatorToSort

更新履歴

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