Skip to content

Instantly share code, notes, and snippets.

@pi-chan
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pi-chan/9797841 to your computer and use it in GitHub Desktop.
Save pi-chan/9797841 to your computer and use it in GitHub Desktop.
EvernoteでマンダラートするスクリプトEvernote5対応版 http://memogakisouko.appspot.com/Evernote.html
(*
このスクリプトの改造、再配布OK
*)
property theNoteBookName : "209.マンダラート" -- 保存するノートブック名
property htmlTemplate : "<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<title><<title>></title>
</head>
<body>
<div>
<table border='1' cellspacing='0'>
<tr>
<td width='200' height='16' style='text-align:left;background-color:#cbdffa;'></td>
<td width='200' height='16' style='text-align:left;background-color:#cbdffa;'></td>
<td width='200' height='16' style='text-align:left;background-color:#cbdffa;'></td>
</tr>
<tr>
<td width='200' height='100' style='text-align:center;background-color:#fff;'></td>
<td width='200' height='100' style='text-align:center;background-color:#fff;'></td>
<td width='200' height='100' style='text-align:center;background-color:#fff;'></td>
</tr>
<tr>
<td width='200' height='16' style='text-align:left;background-color:#cbdffa;'></td>
<td width='200' height='16' style='text-align:left;background-color:#cbdffa;'><<parentLink>></td>
<td width='200' height='16' style='text-align:left;background-color:#cbdffa;'></td>
</tr>
<tr>
<td width='200' height='100' style='text-align:center;background-color:#fff;'></td>
<td width='200' height='100' style='text-align:center;background-color:#fff; font-weight:bold; font-size:140%;'><<title>></td>
<td width='200' height='100' style='text-align:center;background-color:#fff;'></td>
</tr>
<tr>
<td width='200' height='16' style='text-align:left;background-color:#cbdffa;'></td>
<td width='200' height='16' style='text-align:left;background-color:#cbdffa;'></td>
<td width='200' height='16' style='text-align:left;background-color:#cbdffa;'></td>
</tr>
<tr>
<td width='200' height='100' style='text-align:center;background-color:#fff;'></td>
<td width='200' height='100' style='text-align:center;background-color:#fff;'></td>
<td width='200' height='100' style='text-align:center;background-color:#fff;'></td>
</tr>
</table>
</div>
</body>
</html>"
on run
tell application "Evernote"
if (not (notebook named theNoteBookName exists)) then
-- NOTE also check out the "create notebook" command
make notebook with properties {name:theNoteBookName}
end if
display dialog "マンダラートのテーマを入力して下さい" default answer "" buttons {"Cancel", "選択しているノートが親", "新規作成"} default button 3
copy the result as list to {button_pressed, text_returned}
if button_pressed is "cancel" then
return
end if
if text_returned is "" then
display alert "テーマを入力して下さい"
return
end if
set theNoteTitle to text_returned
set tmplate to htmlTemplate
set tmplate to my replaceText(tmplate, "<<title>>", my htmlspecialchars(theNoteTitle))
if button_pressed is "新規作成" then
set tmplate to my replaceText(tmplate, "<<parentLink>>", "")
else
set theSelection to selection as list
if 0 is (count of theSelection) then
beep
display alert "ノートを選択して実行して下さい"
return
end if
set theNote to item 1 of theSelection
set theNotelink to my getNoteLink(theNote)
set prentLinkHTML to "<a href='" & theNotelink & "' style='font-size:14px; text-decoration: none;'>▲</a>"
set tmplate to my replaceText(tmplate, "<<parentLink>>", prentLinkHTML)
end if
set theNote to create note with html tmplate title theNoteTitle notebook theNoteBookName
set notebook1 to notebook "209.マンダラート"
activate
if button_pressed is "選択しているノートが親" then
set theNotelink to my getNoteLink(theNote)
set childLinkHTML to "<a href='" & theNotelink & "' style='font-size:14px; text-decoration: none;'>▼</a>"
my copyHTMLTextToHTMLPasteboard(childLinkHTML)
display alert "copy done"
end if
end tell
end run
on getNoteLink(theNote)
-- ver.2012.08.25.00
tell application "Evernote"
set theNotelink to note link of theNote
if theNotelink is not missing value then
return theNotelink
end if
synchronize
repeat 120 times
set theNotelink to note link of theNote
if theNotelink is not missing value then
return theNotelink
end if
delay 1
end repeat
end tell
return missing value
end getNoteLink
on replaceText(inText, inOld, inNew)
-- ver.2012.06.12.00
set inText to inText as Unicode text
set OriginalDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to inOld as Unicode text
set workData to text items of inText
set AppleScript's text item delimiters to inNew as Unicode text
set workData to workData as Unicode text
set AppleScript's text item delimiters to OriginalDelimiters
return workData
end replaceText
on htmlspecialchars(theText)
-- ver.2012.06.12.00
return do shell script "php -r 'print htmlspecialchars($argv[2]);' '' " & quoted form of theText
end htmlspecialchars
on copyHTMLTextToHTMLPasteboard(theHTMLStr)
-- ver.2012.08.25.00
set theScript to "require 'osx/cocoa';
p = OSX::NSPasteboard.generalPasteboard();
p.declareTypes_owner_([OSX::NSHTMLPboardType,OSX::NSStringPboardType],nil);
p.setString_forType_(ARGV[1].to_ns,OSX::NSStringPboardType);
p.setString_forType_(ARGV[1].to_ns,OSX::NSHTMLPboardType);
"
do shell script "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -e " & quoted form of theScript & " '' " & quoted form of theHTMLStr
end copyHTMLTextToHTMLPasteboard
on urlencode(theText)
-- ver.2012.06.12.00
return do shell script "php -r 'print rawurlencode($argv[2]);' '' " & quoted form of theText
end urlencode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment