Evernote Deposit Renamer

Description

Note from Justin:

I love when people share applied AppleScript projects like these! While you may not use Evernote to track bank deposits like Christian does, you can easily adapt his script to rename and mail a notification about any other type of Evernote item. (I expect this will be especially useful once Evernote lets you get the direct link to the item via AppleScript!)

If you do adapt it, be sure to share your version here. Who knows -- Maybe your idea could inspire someone else to use Evernote in way they didn't know was possible!

I scan checks and a filled-in deposit slip before going to the bank and put the resulting multi-page PDF into Evernote. This script helps me to rename the PDF in a standard way. I'm sure it could be even better but it works for me. I put it into the Scripts menu for easy access. All you do is select the Evernote note you want to rename, then run the script. It asks for an amount and if you didn't make the deposit the same day you ran the script it asks you for a date. The script creates an email (using Mail) that goes to me (and to my office manager but I took her email out of the script here). This way, we both get an email, which we can trap for use in a Rule, announcing the deposit so we know to look in Evernote to see it.

The Code

(*
Veritrope.com
Evernote Deposit Renamer
Authored by Christian Boyce
Version 1.0
September 5, 2011

Project Status, Latest Updates, and Comments Collected at:
http://veritrope.com/code/evernote-deposit-renamer

// CHANGELOG:

1.0  Initial Release


*)


(*
======================================
// USER SWITCHES (YOU CAN CHANGE THESE!)
======================================
*)


--CHANGE THIS TO THE RECIPIENT EMAIL ADDRESS
property recipient_Email : "RECIPIENT EMAIL ADDRESS"

(*
======================================
// MAIN PROGRAM
======================================
*)


-- GET THE AMOUNT (ENTERED BY USER)
set the_amount to display dialog "How much did you deposit? (do not include dollar sign)" default answer "999"
set the_amount to text returned of the_amount

-- PROCESS THE AMOUNT (check for decimal)
if the_amount does not contain "." then
    set the_amount to the_amount & ".00"
end if
--
-- PROCESS THE AMOUNT (add comma if necessary)
set the_offset to offset of "." in the_amount
set number_of_chars_before_decimal to the_offset - 1
if number_of_chars_before_decimal < 4 then
    set the_amount to the_amount
end if
if number_of_chars_before_decimal = 4 then
    set the_amount to character 1 of the_amount & "," & characters 2 thru -1 of the_amount
end if
if number_of_chars_before_decimal = 5 then
    set the_amount to characters 1 thru 2 of the_amount & "," & characters 3 thru -1 of the_amount
end if
set the_amount to "$" & the_amount

-- SET UP THE DATE STRING
set deposit_date to display dialog "Did you make the deposit today?" buttons {"No", "Yes"} default button "Yes"
if button returned of deposit_date is "Yes" then
    set today to current date
    set theMonth to month of today as number
    set theMonth to theMonth as string
    --
    if number of characters of theMonth is 1 then
        set theMonth to "0" & theMonth
    end if
    --
    set theDay to day of today as string
    --
    if number of characters of theDay is 1 then
        set theDay to "0" & theDay
    end if
    --
    set theYear to year of today
    set theDate to theYear & "-" & theMonth & "-" & theDay as string
else
    set the_deposit_date to display dialog "When did you make the deposit? (yyyy-mm-dd)" default answer "yyyy-mm-dd"
    set theDate to text returned of the_deposit_date
end if
--

tell application "Evernote"
    set x to selection
    set new_title to "DEPOSIT: " & theDate & ", " & the_amount & " total"
    set title of item 1 of x to new_title
end tell

--

-- NOW EMAIL NOTICE OF THIS DEPOSIT
tell application "Mail"
    set the_content to "I made a deposit." & return & return & return & ¬
        "Date:        " & theDate & return & return & ¬
        "Amount:  " & the_amount & return & return & return & ¬
        "Look for it in Evernote."
    set the_message to make new outgoing message with properties ¬
        {subject:new_title, content:the_content, sender:recipient_Email}
    tell the_message
        --put in your own email address here
        make new to recipient at end of to recipients with properties {name:recipient_Email}
        --set visible to true
        send the_message
    end tell
end tell