Skip to content

Instantly share code, notes, and snippets.

@swbuehler
Last active December 29, 2015 13:29
Show Gist options
  • Save swbuehler/7677782 to your computer and use it in GitHub Desktop.
Save swbuehler/7677782 to your computer and use it in GitHub Desktop.
Evernote: Update creation dates based on information in note title
tell application "Evernote"
set theNotes to the selection
repeat with eachNote in theNotes
set dateflag to 0
set theTitle to the title of eachNote
if theTitle begins with "DOS" and theTitle ends with "(Notes)" then -- for Medical Notes (DOS yyyy-mm-dd ... (Notes))
try
set the creation date of eachNote to date (do shell script "date -j -f '%F' " & quote & (characters 5 thru 14 of theTitle as string) & quote & " +'%A, %B %d, %Y at %r'")
set dateflag to 1
end try
else if theTitle begins with "DOS" then -- for other Medical Documents (DOS yyyy-mm-dd yyyy-mm-dd)
try
set the creation date of eachNote to date (do shell script "date -j -f '%F' " & quote & (characters 16 thru 25 of theTitle as string) & quote & " +'%A, %B %d, %Y at %r'")
set dateflag to 1
end try
else
-- Try date only, then try date and time (set time to midnight for items with just a date)
try
set the creation date of eachNote to date (do shell script "date -j -f '%F %H%M%S' " & quote & (characters 1 thru 10 of theTitle as string) & " 000000" & quote & " +'%A, %B %d, %Y at %r'")
end try
try
set the creation date of eachNote to date (do shell script "date -j -f '%F %H%M%S' " & quote & (characters 1 thru 17 of theTitle as string) & quote & " +'%A, %B %d, %Y at %r'")
end try
set dateflag to 1
end if
if dateflag is 1 then
set the subject date of eachNote to (the creation date of eachNote)
assign tag "Script Corrected" to eachNote
unassign tag "Script Corrected" from eachNote
end if
end repeat
synchronize
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment