Skip to content

Instantly share code, notes, and snippets.

@metbril
Last active August 29, 2015 14:05
Show Gist options
  • Save metbril/60cd344145c34ebb5bc2 to your computer and use it in GitHub Desktop.
Save metbril/60cd344145c34ebb5bc2 to your computer and use it in GitHub Desktop.
Export selected Evernote items to jrnl using the CLI
(*
Name: Export selected Evernote items to jrnl
Last update: 2014-08-14
Author: Robert van Bregt, www.robertvanbregt.nl
This type of journal is typically used with the jrnl app found at https://maebert.github.io/jrnl/
// TERMS OF USE:
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
Based on Veritrope.com script Export selected items to DayOne
http://veritrope.com/code/export-evernote-items-to-day-one
// CHANGELOG
v1.0 Initial release
v1.1 Fixed error for non-default journals
*)
(*
======================================
// USER SWITCHES (YOU CAN CHANGE THESE!)
======================================
*)
-- IF YOU'D LIKE THE SCRIPT TO CREATE A
-- "HEADER LINE" FOR THE JRNL ENTRY USING
-- THE TITLE OF THE EVERNOTE ITEM, THEN
-- CHANGE THIS VALUE TO "ON"…
property dayHeader : "ON"
-- SET JRNL NOTEBOOK TO CREATE THE ENTRIES IN.
-- LEAVE EMPTY FOR DEFAULT NOTEBOOK
-- SEE ~/.jrnl_config for details
property jrnlNotebook : ""
(*
======================================
// PROPERTIES (USE CAUTION WHEN CHANGING)
======================================
*)
property noteName : ""
property noteCreated : ""
property noteHTML : ""
property noteLink : ""
property note_Date : ""
(*
======================================
// MAIN PROGRAM
======================================
*)
tell application "Evernote"
set selected_Items to selection
repeat with selected_Item in selected_Items
--GET THE EVERNOTE DATA
my getEvernote_Info(selected_Item)
--CONVERT HTML TO PLAIN TEXT
set note_Text to my convert_Plaintext(noteHTML)
--CONVERT DATE TO PLAIN TEXT STRING
set note_Date to my convert_Date(noteCreated)
--MAKE THE NEW ITEM IN DAY ONE
my make_jrnl(noteName, note_Date, note_Text, noteLink)
end repeat
end tell
(*
======================================
// PREPARATORY SUBROUTINES
======================================
*)
--GET THE EVERNOTE DATA
on getEvernote_Info(theNotes)
tell application "Evernote"
try
set noteID to (local id of item 1 of theNotes)
set noteName to (title of item 1 of theNotes)
set noteSource to (source URL of item 1 of theNotes)
set noteCreated to (creation date of item 1 of theNotes)
set noteModified to (modification date of item 1 of theNotes)
set noteTags to (tags of item 1 of theNotes)
set noteAttachments to {attachments of item 1 of theNotes}
set noteAltitude to (altitude of item 1 of theNotes)
set noteENML to (ENML content of item 1 of theNotes)
set noteHTML to (HTML content of item 1 of theNotes)
set noteLat to (latitude of item 1 of theNotes)
set noteLong to (longitude of item 1 of theNotes)
set noteNotebook to (name of notebook of item 1 of theNotes)
set noteLink to (note link of item 1 of theNotes)
end try
end tell
end getEvernote_Info
(*
======================================
// UTILITY SUBROUTINES
======================================
*)
--CONVERT HTML TO PLAIN TEXT
on convert_Plaintext(noteHTML)
set shell_Text to "echo " & (quoted form of noteHTML) & " | textutil -stdin -convert txt -stdout"
set note_Text to do shell script shell_Text
return note_Text
end convert_Plaintext
--CONVERT DATE TO PLAIN TEXT STRING
on convert_Date(noteCreated)
set AppleScript's text item delimiters to ""
set m to ((month of noteCreated) * 1)
set d to (day of noteCreated)
set y to (year of noteCreated)
set t to (time string of noteCreated)
set h to (hours of noteCreated)
set min to (minutes of noteCreated)
set date_String to (y & "-" & m & "-" & d & " " & h & ":" & min) as string
return date_String
end convert_Date
(*
======================================
// MAIN HANDLER SUBROUTINES
======================================
*)
--MAKE ITEM IN JRNL
on make_jrnl(noteName, note_Date, note_Text, noteLink)
if dayHeader is "ON" then
--ADD A "HEADER"
set note_Text to (noteName & return & return & note_Text)
end if
-- prepend date
set note_Text to (note_Date & ": " & note_Text)
set new_jrnl to "echo " & (quoted form of note_Text) & " | '/usr/local/bin/jrnl' " & jrnlNotebook
do shell script new_jrnl without altering line endings
end make_jrnl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment