Safari5.1になってEvernoteプラグインが機能しなくなって久しいですが、いまだ新版はリリースされません(と、書いているとリリースされたりして)。
なので、プリントダイアログからEvernoteにPDFで保存を実行すればできますが、SafariからEvernoteにPDFで保存するのが面倒になりました。
それをAppleScriptで簡単にしてしまおうというのがこの投稿の趣旨です。
で、そのAppleScriptスクリプトですが、以前に色々なアプリケーションからPDFとしてEvernoteに保存するAppleScriptで投稿済みだったりします。SafariだけでなくGoogle Chromeやその他のアプリからも保存が可能です。このスクリプトをSparkやLaunchBarなどから実行すれば、自動的にPDFがEvernoteに保存されます。また、アプリケーションとして保存すれば、Dockに登録して使うこともできます。
ということで、再度掲載しておきます。
-- LaunchBarから実行する場合は以下を有効にする
-- tell application "LaunchBar" to hide
tell application "System Events"
-- AppleScript Editorから実行する場合は以下の2行を有効にする
-- set theName to name of the first process whose frontmost is true
-- set visible of process theName to false
set theName to name of the first process whose frontmost is true
end tell
tell application theName to activate
if theName is "Google Chrome" then
printPDF2EvernoteChrome(theName)
else
printPDF2Evernote(theName)
end if
on printPDF2EvernoteChrome(theName)
tell application "System Events" to tell process theName
try
keystroke "p" using command down
repeat until exists menu button named "PDF" of window 1
delay 0.2
end repeat
tell window 1
click menu button "PDF"
repeat until exists menu item named "PDFをEvernoteに保存" of menu 1 of menu button "PDF"
delay 0.2
end repeat
click menu item named "PDFをEvernoteに保存" of menu 1 of menu button "PDF"
end tell
end try
end tell
end printPDF2EvernoteChrome
on printPDF2Evernote(theName)
tell application "System Events" to tell process theName
try
keystroke "p" using command down
repeat 20 times
if exists menu button named "PDF" of sheet 1 of window 1 then exit repeat
delay 0.2
end repeat
tell sheet 1 of window 1
click menu button "PDF"
repeat 20 times
if exists menu item named "PDFをEvernoteに保存" of menu 1 of menu button "PDF" then exit repeat
delay 0.2
end repeat
click menu item named "PDFをEvernoteに保存" of menu 1 of menu button "PDF"
end tell
end try
end tell
end printPDF2Evernote
Google ChromeからPDFをEvernoteに保存するスクリプトを作成しましたが、同様に他のアプリからも簡単にEvernoteにPDFとして保存したい場合は以下のようなスクリプトになります。一般的なプリントダイアログを利用するアプリであれば利用できると思います。
[追記 2011/05/13] ループ等を修正しました。
[追記 2011/05/13] Chromeへの対応
-- LaunchBarから実行する場合は以下を有効にする
-- tell application "LaunchBar" to hide
tell application "System Events"
-- AppleScript Editorから実行する場合は以下の2行を有効にする
-- set theName to name of the first process whose frontmost is true
-- set visible of process theName to false
set theName to name of the first process whose frontmost is true
end tell
tell application theName to activate
if theName is "Google Chrome" then
printPDF2EvernoteChrome(theName)
else
printPDF2Evernote(theName)
end if
on printPDF2EvernoteChrome(theName)
tell application "System Events" to tell process theName
try
keystroke "p" using command down
repeat until exists menu button named "PDF" of window 1
delay 0.2
end repeat
tell window 1
click menu button "PDF"
repeat until exists menu item named "PDFをEvernoteに保存" of menu 1 of menu button "PDF"
delay 0.2
end repeat
click menu item named "PDFをEvernoteに保存" of menu 1 of menu button "PDF"
end tell
end try
end tell
end printPDF2EvernoteChrome
on printPDF2Evernote(theName)
tell application "System Events" to tell process theName
try
keystroke "p" using command down
repeat 20 times
if exists menu button named "PDF" of sheet 1 of window 1 then exit repeat
delay 0.2
end repeat
tell sheet 1 of window 1
click menu button "PDF"
repeat 20 times
if exists menu item named "PDFをEvernoteに保存" of menu 1 of menu button "PDF" then exit repeat
delay 0.2
end repeat
click menu item named "PDFをEvernoteに保存" of menu 1 of menu button "PDF"
end tell
end try
end tell
end printPDF2Evernote
–
色々なアプリケーションからPDFとしてEvernoteに保存するAppleScriptでより汎用的なスクリプトを公開しています。
–
SafariでページをPDFとしてEvernoteに保存するのは簡単ですが、Google Chromeではプリントメニューを表示してPDFボタンをクリックしてPDFをEvernoteに保存をクリックしなければPDFとしてEvernoteに保存することができません。
のでChromeからEvernoteにページをPDFで自動保存するAppleScriptを作成しました。
準備として、システム環境設定の「ユニバーサルアクセス」にある「補助装置にアクセスできるようにする」をオンにしてください。
以下がスクリプトです。このスクリプトをスクリプトエディタで保存して、スクリプトメニューから実行するなりLaunchBarやQuicksilverから実行するなりすれば、Chromeで開いているページをPDFとしてEvernoteに保存できます。
tell application "Google Chrome" to activate
tell application "System Events" to tell process "Google Chrome"
click menu item named "印刷…" of menu 1 of menu bar item named "ファイル" of menu bar 1 -- keystroke "p" using command down
repeat until exists menu button named "PDF" of window 1
delay 0.2
end repeat
tell window 1
click menu button "PDF"
repeat until exists menu item named "PDFをEvernoteに保存" of menu 1 of menu button "PDF"
delay 0.2
end repeat
click menu item named "PDFをEvernoteに保存" of menu 1 of menu button "PDF"
end tell
end tell
MacのGmail(IMAP)メーラーSparrowを購入してみました。
Mac App Storeでの購入では試用できないので、どんな機能が搭載されているかとか、AppleScriptでどれほどコントロールできるか分からないなど不便です。Webサイトで機能を確認できても、たとえば日本語で検索できるかとか分からないので、Macアプリは高額になりがちですし購入しにくいですね。
さてさてSparrowのAppleScript対応状況ですが、AppleScriptでメールが作成できるようです。
tell application "Sparrow"
set newMessage to make new outgoing message with properties {subject:"This is a title", sender:"myaddress@example.com", content:"This is a pen."}
compose newMessage
end tell
というように作成します。
to recipientをどのように指定すればいいかが分からないです。分かる方コメントください。
それからメールの送信アクションもありますね。
Mail.appでは受信したメールにフィルタをかけることができるので、メールからOmniFocusにTaskを取り込むことが簡単にできました。Sparrowではこのような仕組みがないので、今後はメール→OmniFocusをどう処理するかを検討する必要があります。Sparrowはフィルタ機能を搭載する予定があるか問い合わせてみようと思ってます。
以前からOmniFocusとEvernoteの連携で、EvernoteのノートURIが存在しないのできないと考えていたのですが、OmniFocusのタスクのURIは取得できるので、それを使えばいいじゃないかということで、いくつかAppleScriptを書いてみました。
まず、Evernoteノートを作成するスクリプトです。
新規にノートを作成して、タイトルにタスクのname、ソースURLにタスク(プロジェクト/フォルダ)URIを記入、タグにプロジェクト名を設定、本文にタスクURIとOmniFocusタスクのノートを記入します。本文にもURIを記入するのは、EvernoteでのソースURLの検索方法が無いみたいだからです。
tell front window of application "OmniFocus"
try
set theTrees to selected trees of content
if (count of theTrees) < 1 then
set theTrees to selected trees of sidebar
end if
if (count of theTrees) < 1 then
return
end if
set theSelection to value of item 1 of theTrees
if class of theSelection is folder then
set theURI to "omnifocus:///folder/" & id of theSelection
set theNote to ""
else if class of theSelection is project then
set theURI to "omnifocus:///project/" & id of theSelection
set theNote to ""
else
set theURI to "omnifocus:///task/" & id of theSelection
set theNote to note of theSelection
set theProjectName to name of containing project of theSelection
end if
set theName to name of theSelection
tell application "Evernote"
set newNote to create note with text theURI & return & theNote
set title of newNote to theName
set source URL of newNote to theURI
if (count of theProjectName) > 0 then
if (not (tag named theProjectName exists)) then
make tag with properties {name:theProjectName}
end if
set theTag to tag named theProjectName
assign theTag to newNote
end if
open note window with newNote
activate
end tell
end try
end tell
次にタスクURIをクリップボートに取得するスクリプトです。取得したURIは、既に存在するEvernoteノートに貼り付けるといいです。ソースURLにだけでなく、本文にも貼り付けておかないとURIで検索できません。
tell front window of application "OmniFocus"
try
set theTrees to selected trees of content
if (count of theTrees) < 1 then
set theTrees to selected trees of sidebar
end if
if (count of theTrees) < 1 then
return
end if
set theSelection to value of item 1 of theTrees
if class of theSelection is folder then
set the clipboard to "omnifocus:///folder/" & id of theSelection
else if class of theSelection is project then
set the clipboard to "omnifocus:///project/" & id of theSelection
else
set the clipboard to "omnifocus:///task/" & id of theSelection
end if
end try
end tell
そして、上記二つのスクリプトで作成したEvernoteをタスクURIで検索するためのスクリプトです
tell front window of application "OmniFocus"
try
set theTrees to selected trees of content
if (count of theTrees) < 1 then
set theTrees to selected trees of sidebar
end if
if (count of theTrees) < 1 then
return
end if
set theSelection to value of item 1 of theTrees
if class of theSelection is folder then
set theURI to "omnifocus:///folder/" & id of theSelection
else if class of theSelection is project then
set theURI to "omnifocus:///project/" & id of theSelection
else
set theURI to "omnifocus:///task/" & id of theSelection
end if
tell application "Evernote"
open collection window with query string theURI
activate
end tell
end try
end tell
EvernoteでURLの検索ができればいいのですが…。
ついでに、OmniFocusのプロジェクト名をEvernoteタグにしているので、プロジェクト名でタグを検索するスクリプトです。なんでもNozbeではプロジェクト名とEvernoteのタグが連動するらしいので、同様の機能をAppleScriptで実現しました。複数プロジェクト名での検索には対応してません。
tell front window of application "OmniFocus"
try
set theTrees to selected trees of content
if (count of theTrees) < 1 then
set theTrees to selected trees of sidebar
end if
set theSelection to value of item 1 of theTrees
if class of theSelection is folder then
set theQuery to "tag:" & name of theSelection
else if class of theSelection is project then
set theQuery to "tag:" & name of theSelection
else
set theProject to containing project of theSelection
if theProject is equal to missing value then
return
end if
set theQuery to "tag:" & name of theProject
end if
tell application "Evernote"
open collection window with query string theQuery
activate
end tell
end try
end tell
どのスクリプトもできたてホヤホヤでテストが不十分ですので、バグがあればコメントよろしくです。
Mail.appからOmniFocusに追加してくれるから、Evernoteを挟む必要はないので、なんの役に立つかは分からないけど作ってみた。まぁfind notesのテストみたいなもの。
Evernoteの特定のノートブック(ここではOF)にあるノートをもとにOminFocusのInboxにタスクを作成して、ノートを削除する。
tell application "Evernote"
set matches to find notes "notebook:OF"
repeat with n in matches
set theTitle to title of n
set theContent to HTML content of n
tell application "OmniFocus"
tell front document
make new inbox task with properties {name:theTitle, note:theContent}
end tell
end tell
delete n
end repeat
end tell
問題はコンテンツがHTMLだということ。OFがタグまで表示してくれちゃう。Evernoteからテキストなコンテンツがとれるといいのに。
Evernoteのfind notesは結構時間がかかる。ので、notebookを指定して検索対象を少なくするといい。
LaunchBarからOmniFocusの同期動作を実行したいので、AppleScriptスクリプトを作成。
tell application "OmniFocus"
synchronize document 1
end tell
妻が簡単に画像にタグを付けてEvernoteに保存したいというので、Automatorでアプリケーションを作成した。
エディトリアルというタグをつけて新しいノートを作成する。タイトルはファイル パスそのまま。なので、SafariからD&Dすると、キャッシュのパスになるのはどうにかした方がいいかも。

Minnu’s Filer2がMacで使えるようになってたので、導入した。
ので、早速ショートカットキーで起動するようにした。
Sparkで以下のAppleScriptを実行。
tell application "Terminal"
activate
tell application "System Events" to keystroke "t" using command down
do script "mfiler2" in last tab of window 1
end tell