2013-01-05
■Evernoteで指定したノートブックに表示を切り替えるAppleScript
環境
- Mac OS X 10.8.2
- Evernote 3.3.1
問題
Evernoteで指定したノートブックに表示を切り替えたい。
マウスを使わずに切り替えたい。
解決方法
下記のスクリプトを実行する。
実行するとノートブックの一覧が表示されるので選択すると、
表示するノートブックが切り替わる。
# Evernoteのノートブック名のリストを取得します。 on getNotebookNames() set nameList to {} tell application "Evernote" repeat with aNotebook in notebooks set notebookName to name of aNotebook set nameList to nameList & notebookName end repeat end tell return sortList(nameList) end getNotebookNames # リストをソートします。 on sortList(aList) set oldDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {ASCII character 10} set str to aList as string set str to do shell script ¬ "echo " & quoted form of str & " | sort -f" set sortedList to paragraphs of str set AppleScript's text item delimiters to oldDelimiters return sortedList end sortList # リストから選択肢を表示して選択された要素番号を取得します。 on chooseFromList(aMessage, aList, aDefault) activate set anAnswer to choose from list aList with prompt aMessage ¬ default items {aDefault} if anAnswer = false then return false end if set anAnsweredText to contents of item 1 of anAnswer set foundIndex to 0 repeat with anItem in aList set s to contents of anItem if s is equal to anAnsweredText then return 1 + foundIndex end if set foundIndex to foundIndex + 1 end repeat return false end chooseFromList set notebookNames to getNotebookNames() set firstNotebookName to item 1 of notebookNames set selectedIndex to chooseFromList("Choose notebook", notebookNames, firstNotebookName) tell application "Evernote" if selectedIndex = false then activate return end if set notebookName to (item selectedIndex of notebookNames) repeat with w in windows if class of w = collection window then set query string of w to "notebook:\"" & notebookName & "\"" activate return end if end repeat end tell
