Jump to content
vladcampos

Hazel + AppleScript to change note creation date

Recommended Posts

I have to import several images to an Evernote notebook but I need to have each note creation date changed to the image creation date. I'm trying to do it using Hazel and AppleScript but had no success changing the note creation date. I set Hazel to monitor a folder on my Mac looking for new images and I have the following script sending them to Evernote:

tell application "Evernote"

activate

create note from file theFile notebook {"Test"}

end tell

I'm not a developer and have little experience with AppleScript. That said I have already tried my best using, for example, "creationDate" to completing the script and could never get it to change the creation date. All I got so far was a loop importing the same file over and over again or an error from Hazel.

Would appreciate some help from you guys. Thank you!

Share this post


Link to post
2 hours ago, vladcampos said:

I have to import several images to an Evernote notebook but I need to have each note creation date changed to the image creation date. I'm trying to do it using Hazel and AppleScript but had no success changing the note creation date. I set Hazel to monitor a folder on my Mac looking for new images and I have the following script sending them to Evernote:

tell application "Evernote"
activate
create note from file
theFile notebook {"Test"}
end tell

 

 

You can do it all in one statement but I prefer

 

set importedNote to (create note .......)

set creation date of importedNote to .......

 

Here's the dictionary description - you have the Notebook attribute

 

 

create notev : Create a new note. You must specify exactly one of 'from file', 'from url', 'with text', or 'with html'.

create note

[from file file] : Clip the contents of the specified file.

[from url text] : Clip the contents of the specified URL.

[with text text] : Create a new note using the specified plain-text as content.

[with html text] : Create a new note using the specified html as content.

[with enml text] : Create a new note using the specified ENML as content. Do not include the <en-note> tags, only what should be between them.

[title text] : Title for the new note.

[notebook text or notebook] : Notebook in which to place the note. Can be the name of a notebook or an object reference. If no notebook with the specified name exists a new one is created. If no notebook is specified, the default notebook for the account is used.

[tags list of text or list of tag] : Tags to assign to the new note. Can be the name of a tag or an object reference. If no tag with the specified name exists a new one is created.

[attachments list of file] : Files to attach to the note.

[created date] : Creation date for the new note. Defaults to now.

→ note : The new note.

Share this post


Link to post

Thanks for replying but I'm afraid I did't get the second line. I tried several alternatives to complete the dots and none of them worked.

tell application "Evernote"

activate

set importedNote to (create note from file theFile notebook {"Test"})

set creation date of importedNote to ...

end tell

Share this post


Link to post
8 minutes ago, vladcampos said:

Thanks for replying but I'm afraid I did't get the second line. I tried several alternatives to complete the dots and none of them worked.

To complete the set creation date line, you need to specify the date, as in 20160321

Is your question: How to identify the date of the image file?

Share this post


Link to post
2 minutes ago, DTLow said:

Is your question: How to determine the date of the image file?

Yes. I want to automatically set the note creation date based on the image creation date. And each image has its own creation date. I choose to use Hazel because this is a long term activity and I'll have a this folder where I can send move images to and let Hazel + script to work on them.

Share this post


Link to post
On March 22, 2016 at 8:05 PM, vladcampos said:

Yes. I want to automatically set the note creation date based on the image creation date. And each image has its own creation date. I choose to use Hazel because this is a long term activity and I'll have a this folder where I can send move images to and let Hazel + script to work on them.

I also have an import folder triggered by Folder Actions and Applescript
A script to do this is packaged here http://veritrope.com/evernote-desktop-folder/

I don't use Hazel, but understand it delivers the filename to your scriptlet for processing.
Can it give you the creation date?

Another line of thought is to Tell Application "Finder" ..... 
Thats all I know for this - I haven't used it much - Perhaps our more talented Applescript users have more details.

Share this post


Link to post
4 hours ago, vladcampos said:

I have to import several images to an Evernote notebook but I need to have each note creation date changed to the image creation date.

I have NOT tested this code (it was pulled from a complicated script), but it should serve the purpose of showing you how to set the Note Creation Date to the File Creation Date:


###	 WARNING:  THIS SCRIPT IS  UNTESTED ####
#		USE ONLY FOR SHOWING AN EXAMPLE 

### CHANGE NOTEBOOK AND TAGS FOR YOUR ACCOUNT ###

set nbName to "YourNBName"
set tagList to {"Tag1", "Tag2"}

tell application "Evernote"
	repeat with oFile in fileList
		
		-- GET FILE DATE & NAME
		
		tell application "Finder"
			set creationDate to creation date of oFile
			set file_name to (name of (oFile))
			set file_ext to (name extension of (oFile))
		end tell
		
		set rootName to file_name
		if (file_ext ≠ "") then set rootName to text 1 thru -((count file_ext) + 2) of file_name
		
		set titleNote to rootName
		set bodyNoteHTML to "<B>File: " & file_name & "</B><BR>"
		
		-- CREATE EVERNOTE NOTE WITH FILE ATTACHED --
		
		create note title titleNote with html bodyNoteHTML notebook nbName tags tagList created creationDate attachments oFile
		
	end repeat
end tell

 

Share this post


Link to post
13 hours ago, vladcampos said:

Yes. I want to automatically set the note creation date based on the image creation date.

I may have pointed you in the wrong direction with Finder.  
Finder gives you the file creation date.
You might want the image creation date, stored as EXIF data (for example "2015:04:30 17:15:53")

I fouund this code sample

tell application "Image Events" to set exifDate to (value of metadata tag "creation" of (openeachFile))
set {hmsto {word 4, word 5, word 6} of exifDate
set daySeconds to 60 * 60 * h + 60 * m + s

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...