Created
November 25, 2014 04:35
-
-
Save rashita/5b5f14685094fa3fb00e to your computer and use it in GitHub Desktop.
Evernoteにwikiのリンク作成的な機能を付加するスクリプト。初回の起動時は、白紙のノートを選ぶことになります。それでセッティングは終了。以降、Evernoteでノートのテキストを選択して、スクリプトを起動させると、選択したテキストがタイトルになったノートが作成され、元のノートのテキストがノートリンクになります。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
property stocknotelink : "" | |
property stocknbtitle : "無題ノート" --Blanknoteのタイトル | |
property stocknb : "stock" --Blanknoteを保存するノートブック | |
--ノートリンクが空っぽのときは、ノートの選択から始める。 | |
set nowclipboard to the clipboard --クリップボードを使うので、今入っているものを避難 | |
if stocknotelink is "" or stocknotelink is missing value then | |
display dialog "無題ノートを1つ選択してから、OKボタンを押してください。" | |
tell application "Evernote" | |
set selectedNotes to selection | |
set n to count selectedNotes | |
if n is not 1 then | |
display alert "ノートを一つだけ選択してください。" | |
return | |
end if | |
set anote to item 1 of selectedNotes | |
if note link of anote is not missing value then | |
set stocknotelink to note link of anote | |
else | |
display alert "ノートの同期をかけてから再びアプリを起動してください。" | |
return | |
end if | |
end tell | |
return --一度アプリを終了させる | |
end if | |
--ノートリンクの処理は以上 | |
--ノートリンクが保持されている場合は、以下から処理が始まる | |
tell application "Evernote" --Evernoteに呼びかける | |
activate --Evernoteをアクティブにする | |
set selectedNotes to selection --選択中のノートを取得 | |
set n to count selectedNotes | |
if n is not 1 then | |
display alert "ノートを一つだけ選択してください。" | |
return | |
end if | |
set selectnotebook to notebook of item 1 of selectedNotes | |
set selecttitle to title of item 1 of selectedNotes | |
tell application "System Events" | |
tell application process "Evernote" | |
delay 0.3 --ちょっと待つ | |
keystroke "c" using command down | |
delay 0.2 | |
set selectword to paragraphs of (the clipboard as text) | |
end tell | |
end tell | |
if selectword is not "" then | |
repeat with i in selectword | |
if i is not "" then | |
set selectwordtitle to i | |
exit repeat | |
end if | |
end repeat | |
end if | |
set blanknote to find note stocknotelink | |
log blanknote | |
set dataHTML to my htmlToRawData("<a href=\"" & (note link of blanknote) & "\" style=\"color:#69aa35;\">" & selectwordtitle & "</a>") | |
set the clipboard to {«class HTML»:dataHTML} | |
tell application "System Events" | |
tell application process "Evernote" | |
keystroke "v" using command down | |
end tell | |
end tell | |
set title of blanknote to selectwordtitle | |
move blanknote to selectnotebook | |
set newnote to create note title stocknbtitle notebook stocknb with text " " | |
synchronize | |
delay 1 | |
repeat 1000 times | |
set stocknotelink to note link of newnote | |
if stocknotelink is not missing value then | |
exit repeat | |
end if | |
delay 0.5 | |
end repeat | |
end tell | |
set the clipboard to nowclipboard --避難させておいたものをクリップボードに戻す | |
on htmlToRawData(htmlText) --師匠からの頂き物 | |
set hexData to my hexdump(htmlText) | |
return run script "«data HTML" & hexData & "»" | |
end htmlToRawData | |
on hexdump(aText) | |
return do shell script "echo " & quoted form of aText & "| hexdump -v -e '/1 \"%02X\"'" | |
end hexdump |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment