title: Setting the correct date on notes imported to iCloud
body: <p>I'm using the following script (which I found online) to import old notes into iCloud, via the Notes OS X app. The import works fine, but all the imported notes show as created at time of import.</p>
  
  <p>I wrote in a section of code that should copy the date from the original note file and set the new note's date to that, but for some reason it isn't working. The date is being copied correctly, and as far as I can tell, the second part executes as well, since there isn't any error, but the date always ends up being the import date.</p>
  
  <p>If anyone can spot the issue or has any ideas, I would very much appreciate it!</p>
  
  <pre><code>-- choose the folder with the notes
  set notesFolder to choose folder
  
  -- find all the files in that folder
  tell application "Finder"
      set noteFiles to (files of entire contents of notesFolder) as alias list
  end tell
  
  -- get the name of the account that you want to add the notes to
  set accountName to getNameOfTargetAccount()
  
  -- get the name of the folder to add the notes to
  set folderName to getNameOfTargetFolderOfAccount(accountName)
  
  -- make sure the folder exists in Notes
  tell application "Notes"
      tell account accountName
          if not (exists folder folderName) then make new folder with properties {name:folderName}
      end tell
  end tell
  
  repeat with noteFile in noteFiles
      -- get the note name from the file name and the corresponding dates
      set {noteName, ext} to getName_andExtension(noteFile)
  
      tell application "Finder"
          set noteModified to modification date of noteFile
          set noteCreated to creation date of noteFile
  
      end tell
  
      -- get the file's text as html
      if ext is "html" then
          set noteText to read noteFile
      else
          -- convert the file's contents into html code
          set noteText to do shell script "/usr/bin/textutil -stdout -convert html " &amp; quoted form of POSIX path of noteFile &amp; " | /usr/bin/tidy -ib -utf8"
      end if
  
      -- add the note to the folder
      tell application "Notes"
          tell account accountName
              tell folder folderName
                  make new note with properties {name:noteName, body:noteText, modification date:noteModified, creation date:noteCreated}
              end tell
          end tell
      end tell
  end repeat
  
  
  (****************** SUBROUTINES *****************)
  -- this lets you choose which acount you want to target
  -- if there's only 1 account then that account name is returned
  on getNameOfTargetAccount()
      tell application "Notes"
          if (count of accounts) is greater than 1 then
              set theseAccountNames to the name of every account
              set thisAccountName to choose from list theseAccountNames with prompt "Add note to which account?"
              if thisAccountName is false then error number -128
              set thisAccountName to thisAccountName as text
          else
              set thisAccountName to the name of first account
          end if
          return thisAccountName
      end tell
  end getNameOfTargetAccount
  
  -- this lets you choose which folder you want to target from an account
  -- if there's only 1 folder then that folder name is returned
  on getNameOfTargetFolderOfAccount(accountName)
      set folderName to missing value
      tell application "Notes"
          tell account accountName
              if (count of folders) is greater than 1 then
                  set theseFolderNames to the name of every folder
                  set folderName to choose from list theseFolderNames with prompt "Add note to which folder?"
                  if folderName is false then error number -128
                  set folderName to folderName as text
              else
                  set folderName to the name of first folder
              end if
          end tell
      end tell
      return folderName
  end getNameOfTargetFolderOfAccount
  
  on getName_andExtension(f)
      set f to f as text
      set {name:nm, name extension:ex} to info for file f without size
      if ex is missing value then
          set ex to ""
      else
          set nm to text 1 thru ((count nm) - (count ex) - 1) of nm
      end if
      return {nm, ex}
  end getName_andExtension
  </code></pre>