Jump to content

Creating a note with AppleScript, but changing the date (Evernote Mac)


Recommended Posts

I am trying to create a Hazel script that takes a date from the file Hazel is making an Evernote note from and uses that as the creation date of the note.  Can anyone tell me how to do this?  I've got a script that can do this after the fact, but I can't seem to get it to work within Hazel.

 

Thanks in advance!

Jamie

Link to comment
  • Level 5*

Here's a line from one of my Evernote Applescripts that shows how to set the Note Created Date to the File Date at the time the Note is created:

tell application "Finder"

set creationDate to creation date of new_item

set file_name to (name of (new_item))

end tell

 

create note title file_name with html theBody created creationDate attachments new_item

Link to comment

This is helpful.  Unfortunately, I'm trying to actually use the file name for the creation date rather than the file creation date.  Here's what I've done (and that's failing for some unknown reason):

set noteyears to {"2014", "2015", "2016"}set notemonths to {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"}set notedays to {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"}set notetitle to title of theFileset noteyear to ((characters 1 thru 4 of notetitle) as string)set notemonth to ((characters 6 thru 7 of notetitle) as string)set noteday to ((characters 9 thru 10 of notetitle) as string)tell application "Evernote"	activate	if (noteyears contains noteyear and notemonths contains notemonth and notedays contains noteday) then		set creationDate to current date		set year of creationDate to noteyear as integer		set month of creationDate to notemonth as integer		set day of creationDate to noteday as integer		set time of creationDate to 0		create note from file theFile notebook {"Receipts"} tags {"receipts", "expenses"} created date creationDate	else		create note from file theFile notebook {"Receipts"} tags {"receipts", "expenses"}	end ifend tell

Any thoughts?  Thank you for responding so quickly by the way!

Link to comment
  • Level 5*

@Publius:  As you probably know, string and date handling in Applescript is a much bigger challenge than most other languages.  I don't have a specific solution, but I'd suggest this:

  1. Try hard-coding the date string, convert to date, and output both to make sure things are working like you expect.
  2. Try hard-coding the date, and try creating the EN Note to make sure you've got everything else correct.
  3. Do a Google on "Applescript dates" to see if you can find some good examples for converting strings to dates.

HTH.

Link to comment

Unrelated comment on AppleScript style: 

 

Your constants "noteyears", "notemonths", and "notedays" would more logically be defined as properties, not variables initialized with "set" statements. Like: 

 

property noteyears: {"2014", "2015", "2016"}

 

It doesn't really apply to your case, but properties are cool because you can change their value in your code and the new value will be remembered on successive launches (until you recompile the script). 

Link to comment
  • 3 months later...

This is helpful.  Unfortunately, I'm trying to actually use the file name for the creation date rather than the file creation date.  Here's what I've done (and that's failing for some unknown reason):

set noteyears to {"2014", "2015", "2016"}set notemonths to {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"}set notedays to {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"}set notetitle to title of theFileset noteyear to ((characters 1 thru 4 of notetitle) as string)set notemonth to ((characters 6 thru 7 of notetitle) as string)set noteday to ((characters 9 thru 10 of notetitle) as string)tell application "Evernote"	activate	if (noteyears contains noteyear and notemonths contains notemonth and notedays contains noteday) then		set creationDate to current date		set year of creationDate to noteyear as integer		set month of creationDate to notemonth as integer		set day of creationDate to noteday as integer		set time of creationDate to 0		create note from file theFile notebook {"Receipts"} tags {"receipts", "expenses"} created date creationDate	else		create note from file theFile notebook {"Receipts"} tags {"receipts", "expenses"}	end ifend tell

Any thoughts?  Thank you for responding so quickly by the way!

You may try not doing this:

noteyears contains noteyear and notemonths contains notemonth and notedays contains noteday

 

and instead splitting on a "/" or whatever the delimiter is and comparing to make sure it has the correct number of characters.  You are just doing a contains search, whihc it may be hanging up on, try display a dialog of the variables or look in the AS log and make sure it is getting them.  Even "" can return true as in reality, some languages consider a blank character something, so if ("") will yield true, if (NULL) will sometimes be true, others not, depends on the language.  AS needs a better date hammdler, you could try using UNIX timestamp from epoch as your date and manipulate that in seconds since the epoch.

Link to comment
  • 9 months later...
On 18 Dec 2014 at 6:06 AM, Publius said:

I am trying to create a Hazel script that takes a date from the file Hazel is making an Evernote note from and uses that as the creation date of the note.  Can anyone tell me how to do this?  I've got a script that can do this after the fact, but I can't seem to get it to work within Hazel.

 

Thanks in advance!

Jamie

I'm not sure if you already worked this one out, but a solution I successfully use can be found here:

http://www.documentsnap.com/evernote-hazel-pdf-date-applescript/

 

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...