Created
April 2, 2012 22:08
-
-
Save sflinter/2287556 to your computer and use it in GitHub Desktop.
Update the creation date on Evernote notes based on their title
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
opts.on("-n", "--notebook NAME", String) do |notebook| | |
Evernote::Scripts.new.change_creation_date(notebook) | |
end | |
opts.parse(ARGV) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment