Skip to content

Instantly share code, notes, and snippets.

@liudangyi
Last active December 9, 2015 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save liudangyi/4324843 to your computer and use it in GitHub Desktop.
Save liudangyi/4324843 to your computer and use it in GitHub Desktop.
Create a new note using a text file (e.g. Todo.taskpaper under document folder) in Evernote, and sync with it every 20 min.
-- e.g. replaceString("Hello hello", "hello", "Bye") --> "Hello Bye"
on replaceString(theText, oldString, newString)
-- ljr (http://applescript.bratis-lover.net/library/string/)
local ASTID, theText, oldString, newString, lst
set ASTID to AppleScript's text item delimiters
try
considering case
set AppleScript's text item delimiters to oldString
set lst to every text item of theText
set AppleScript's text item delimiters to newString
set theText to lst as string
end considering
set AppleScript's text item delimiters to ASTID
return theText
on error eMsg number eNum
set AppleScript's text item delimiters to ASTID
error "Can't replaceString: " & eMsg number eNum
end try
end replaceString
set s to read alias (((path to documents folder) as text) & "task.taskpaper") as «class utf8»
set s to replaceString(s, "&", "&")
set s to replaceString(s, "<", "&lt;")
set s to replaceString(s, "
", "</div><div>")
set s to "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><body><div>" & s & "</div></body></html>"
tell application "System Events"
if exists (processes where name is "Evernote") then
tell application "Evernote"
repeat with n in notes of notebooks
if title of n is "Todo" then
exit repeat
end if
end repeat
if title of n is not "Todo" then
set n to create note title "Todo" with text ""
end if
set HTML content of n to s
end tell
end if
end tell
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>TaskPaper2Evernote</string>
<key>ProgramArguments</key>
<array>
<string>open</string>
<string>/Users/Leedy/Development/AppleScript/TaskPaper2Evernote.app</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>1200</integer>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment