Export MacJournal to Evernote

Description

This script exports a copy of all the entries in a selected MacJournal and saves them into Evernote while providing Growl Notification of its progress! FYI - Although MacJournal uses tagging, it isn't currently possible to read those tags via AppleScript. Therefore, you'll need to tag your items once they've been imported into Evernote.

Change Log:

  • 1.00 (October 2, 2009) INITIAL RELEASE OF SCRIPT

The Code

(*
http://veritrope.com
MacJournal to Evernote Exporter
Version 1.0
October 2, 2009

Project Status, Latest Updates, and Comments Collected at:
http://veritrope.com/tips/macjournal-evernote-export
           
Installation: Just double-click on the script!

CHANGELOG:
1.00    INITIAL RELEASE
*)


property theNum : "0"
property EVnotebook : ""
property thename : ""
property theText : ""

(* CHECK FOR GROWL *)
tell application "System Events"
    set processnames to name of every process
end tell
if "GrowlHelperApp" is in processnames then
    tell application "GrowlHelperApp"
        set the allNotificationsList to {"Success Notification", "Failure Notification"}
        set the enabledNotificationsList to {"Success Notification", "Failure Notification"}
        register as application ¬
            "MacJournal to Evernote" all notifications allNotificationsList ¬
            default notifications enabledNotificationsList ¬
            icon of application "Evernote"
    end tell
end if

(*MAIN PROGRAM *)
tell application "MacJournal"
    set theNum to 0
    try
        set this_selection to my Journal_List()
        set EVnotebook to my Notebook_List()
        repeat with this_entry in this_selection
            if the (content file of this_entry) is not equal to missing value then
                set theText to (content file of this_entry)
            else
                set theText to (the plain text content of this_entry)
            end if
            set thename to (the name of this_entry)
            set theDate to (the date of this_entry)
           
            tell application "Evernote" -- CREATE THE NOTE FROM ITEM
                set n to create note from file theText ¬
                    title thename ¬
                    notebook EVnotebook ¬
                    created theDate
            end tell
           
            set theNum to theNum + 1
        end repeat
       
        if "GrowlHelperApp" is in processnames then
            tell application "GrowlHelperApp" -- GROWL SUCCESS
                notify with name ¬
                    "Success Notification" title ¬
                    "Import Success" description "Successfully exported " & theNum & ¬
                    " Notes to the " & EVnotebook & " notebook in Evernote" application name "MacJournal to Evernote"
            end tell
        else
            if "GrowlHelperApp" is in processnames then
                tell application "GrowlHelperApp" -- GROWL FAILURE FOR NO SELECTION
                    notify with name ¬
                        "Failure Notification" title ¬
                        "Import Failure" description ¬
                        "No headline or tab selected!" application name "MacJournal to Evernote"
                end tell
            else if "GrowlHelperApp" is not in processnames then -- NON-GROWL ERROR MSG. FOR NO SELECTION
                display dialog "No headline or tab selected!" with icon 0
            end if
        end if
       
        (* ERROR HANDLING *)
    on error errText number errNum
        if "GrowlHelperApp" is in processnames then
            tell application "GrowlHelperApp" -- GROWL FAILURE FOR ERROR
                notify with name ¬
                    "Failure Notification" title ¬
                    "Import Failure" description "Failed to export " & return & thename & ¬
                    ""  due to the following error: " & return & errText ¬
                    application name "
MacJournal to Evernote"
            end tell
        else if "
GrowlHelperApp" is not in processnames then -- NON-GROWL ERROR MSG. FOR ERROR
            display dialog "
Item Failed to Import: " & errNum & return & errText with icon 0
        end if
    end try
end tell

(* SUBROUTINES *)
--EVERNOTE NOTEBOOK SELECTION SUBROUTINE
on Notebook_List()
    tell application "
Evernote"
        activate
        set listOfNotebooks to {} (*PREPARE TO GET EVERNOTE'S LIST OF NOTEBOOKS *)
        set EVNotebooks to every notebook (*GET THE NOTEBOOK LIST *)
        repeat with currentNotebook in EVNotebooks
            set currentNotebookName to (the name of currentNotebook)
            copy currentNotebookName to the end of listOfNotebooks
        end repeat
        set Folders_sorted to my simple_sort(listOfNotebooks) (*SORT THE LIST *)
        set SelNotebook to choose from list of Folders_sorted with title "
Select Evernote Notebook" with prompt ¬
            "
Current Evernote Notebooks" OK button name "OK" cancel button name "New Notebook" (*USER SELECTION FROM NOTEBOOK LIST *)
        if (SelNotebook is false) then (*CREATE NEW NOTEBOOK OPTION *)
            set userInput to ¬
                text returned of (display dialog "
Enter New Notebook Name:" default answer "")
            set EVnotebook to userInput
        else
            set EVnotebook to item 1 of SelNotebook
        end if
    end tell
end Notebook_List

--MACJOURNAL JOURNAL SELECTION SUBROUTINE
on Journal_List()
    tell application "
MacJournal"
        activate
        every journal entry in (choose journal)
    end tell
end Journal_List

--SORT SUBROUTINE
on simple_sort(my_list)
    set the index_list to {}
    set the sorted_list to {}
    repeat (the number of items in my_list) times
        set the low_item to "
"
        repeat with i from 1 to (number of items in my_list)
            if i is not in the index_list then
                set this_item to item i of my_list as text
                if the low_item is "
" then
                    set the low_item to this_item
                    set the low_item_index to i
                else if this_item comes before the low_item then
                    set the low_item to this_item
                    set the low_item_index to i
                end if
            end if
        end repeat
        set the end of sorted_list to the low_item
        set the end of the index_list to the low_item_index
    end repeat
    return the sorted_list
end simple_sort

6 Responses to “Export MacJournal to Evernote”

  1. Ninjahippies June 16, 2011 at 6:10 pm #

    This script works beautifully with Macjournal 5.2.7 and Evernote Version 2.2.1 (154267).

    You have NO IDEA how much time this script has saved me. THANK YOU THANK YOU THANK YOU!

    • Justin Lancy June 16, 2011 at 6:14 pm #

      A “Triple Thank You”?!? WOW! 😉

      Seriously — This is why I share these scripts here and it’s incredibly gratifying to know that they’re helpful to my fellow Mac users. Thank YOU for taking the time to leave the comment.

  2. Adam June 28, 2011 at 4:28 am #

    I am getting the following error on line 43 when I try to save the script: “Expected “,” but found class name.” I wish I knew how to fix it, because this would be absurdly useful.

    • Justin Lancy June 28, 2011 at 11:00 am #

      Adam,

      Could you use the Bug Reporter to send me some system information, including:

      • Version Number of MacJournal
      • Version Number of Evernote
      • Version Number of OS X
      • The Name and Version Number of the web browser you used to grab the script
  3. JM Palacios February 5, 2012 at 7:05 pm #

    Thanks for this! I made a modification since I just wanted to export selected entries. Just commented out one line and added the line below it.

    --MACJOURNAL JOURNAL SELECTION SUBROUTINE
    on Journal_List()
        tell application "MacJournal"
            activate
            --every journal entry in (choose journal)
            selected entries
        end tell
    end Journal_List

    The script could be modified with some if or try statements to to that automatically if entries are selected, but I’ll leave that exercise to someone else.

    • Justin Lancy February 5, 2012 at 9:26 pm #

      This is a GREAT modification – THANKS! 🙂

      And if people are interested, I’ll take a swing at updating the code with the if/try statements that JM is referring to.