Skip to content

Instantly share code, notes, and snippets.

@sflinter
Created November 24, 2012 19:39
Show Gist options
  • Save sflinter/4141142 to your computer and use it in GitHub Desktop.
Save sflinter/4141142 to your computer and use it in GitHub Desktop.
Update the creation date on all Evernote notes to match the date in their title
#!/usr/local/bin/macruby
# Update the creation date on all Evernote notes to match the date in their title
# The date format in the title must be 'yyyymmdd'
# Requires macruby to run
require 'date'
require 'optparse'
framework "ScriptingBridge"
module Evernote
class Scripts
def initialize
@evernote = SBApplication.applicationWithBundleIdentifier("com.evernote.Evernote")
end
def change_creation_date(nb_name)
@evernote.notebooks
.find_all { |nb| nb.name =~ /#{nb_name}/ }
.each do |notebook|
puts "* #{notebook.name}"
notebook.notes.each do |note|
if note.title =~ /(20[01][0-9])([0-9]{2})([0-9]{2})/
d = Date.new($1.to_i, $2.to_i, $3.to_i)
if note.creationDate.strftime("%Y-%m-%d") == d.to_s
puts " - #{note.title}"
puts " : #{note.creationDate}"
puts " : Creation date correct: #{d}"
else
note.creationDate = Time.local(d.year, d.month, d.day,
note.creationDate.hour, note.creationDate.min,
note.creationDate.sec, note.creationDate.usec)
puts " - changed #{note.title} to #{note.creationDate}"
end
end
end
end
end
end
end
opts = OptionParser.new
@notebook = "@Inbox"
opts.on("-n", "--notebook NAME", String) do |notebook|
@notebook = notebook
end
opts.parse(ARGV)
Evernote::Scripts.new.change_creation_date(@notebook)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment