Jump to content

AppleScript to create note from template


Recommended Posts

I've made an AppleScript for creating a new note from a template. You can choose a template from a pop up list of template notes which are stored in a single template notebook. You can then choose where (in which existing notebook) to place the new note. Next you can enter a title for your new note. The script can insert a date/time stamp into your note. You can configure the name of the template notebook (default '_templates') and the value of the template tag (default 'template'). The new note can be configured to open in an existing EN window or in its own window.

You can view the code here. The script is attached.

I hope you'll find this script usefull. Please comment.

evernote_new_note_from_template.scpt.zip

Link to comment

Hi JMichael,

Here are some answers to your question.

How the script is initiated

Download evernote_new_note_from_template.zip from this post. Unpack the zip. Copy evernote_new_note_from_template.scpt to /Users/<username>/Library/Scripts

Activate Script Menu (Mac OS Lion):

Run /Applications/Utilities/AppleScript Editor.app

Goto AppleScript Editor preferences

In the General panel check 'Show script menu in menu bar'

Now you should see this icon post-88287-0-19964100-1329476282.gif in the menu bar, which represents Script Menu.

Click the Script Menu icon and click evernote_new_note_from_template

To activate the script with a keyboard hotkey, install FastScript. It works exactly like Script Menu, but now with the possibility of assigning hotkeys to scripts.

Is it part of the Evernote menu?

Noop.

Good luck!

Link to comment

Great script! I have been looking for this.

And, if you open it in applescript, you have included the configuration instructions for noobes like me. Thank you!

Quick (I hope!) question: I would like to set the title of the new note to read something like Feb 17, 2012 - Fri.

I can see where to change it, but don't know what to change it to so that it automatically defaults to that form, saving me the 10 seconds it would take me to type in the title.

Can you help with that?

Link to comment

Hai McKee,

To get the title you want, open the script and find the subroutine 'on create_new_note_title from template_title'.

Delete and insert code as shown in the image below (don't known how to resize; click on image for larger view):

post-88287-0-04955000-1329498013_thumb.p

If you want 'Feb' in stead of 'February' you'll have to play around a bit with applescript's string manipulation.

Good luck.

Link to comment
  • Level 5*

If you want 'Feb' in stead of 'February' you'll have to play around a bit with applescript's string manipulation.

Good luck.

You will need good luck with this. The AppleScript string functions are the most limiting and difficult to use of any language I have used in many, many years. But then it may be that I am just a novice at AppleScript. :)

Link to comment

Thanks Guys. I don't really need it abreviated. Especially not if I have to fight with the script and risk just totally messing it up and wasting a ton of time. Just to be able to keep the format close to what I was manually using is great. The template script is a real time saver as it is.

M

Link to comment

Oh, hey, I just noticed this. Thanks for the props in your code. I see how you added the time-stamp feature to the version I posted earlier. That's a nice feature.

I add keyboard shortcuts without using FastScript by saving the scripts as an Application and then creating an Automator service to run the application. Out of curiosity, what else does FastScript offer?

Link to comment

I'm working on a next version were you can add [title] in the note's content. That will be replaced with the title note. I think this to be useful. Most of the time when I create a note in EverNote, I want the first line of the note to be the note's title.

About FastScripts: the only interesting difference with Apple's Script Menu (as far as I'm concerend) is that you can define keyboard shortcuts (max. 10 for the free version) for running scripts.

Link to comment

Koen, Thanks for this very usefull script!

I have implemented in a way other than that indicated in this post.

What I do is:

- create a new service in automator, and add the action 'run applescript'.

- copy/paste de code in the run applescript windows in automator.

- I can also assign a shortcut to the service through keyboard preferences. For example I assign Ctrl-Shift-N, so pressing this keys in EN the service is ejecuted. Very nice!

and it works most of the script, except the routine 'simple_sort'.

When i try to run the script 'as is' from automator, the code of this routine is highlighted and mensage windows say 'Sintax Error: Part of this expression returned no result.'

If I deleted the sentences that call this routine, all works fine (but the list box are obviously unsorted).

The funny thing is that this happens only when I run the script as a action in automator.

If I run the script from script editor, all work fine, include the 'simple_sort' routine.

Do you know any reason for this behavior?

Thanks in advance for the reply, and many thanks again for the code...

Link to comment

That error -- which also happens in the template script I posted -- is because of some idiosyncracies running scripts from Automator. If you save them from the AppleScript menu as Applications, rather than scripts, and then run the applications from Automator, this doesn't happen. There's a little bit more detail on my github site.

Link to comment

gtuckerkellog,

I follow your suggestion, the workflow works (it is, the list are sorted, and I can add a new note from template) but at the end I get a message error that says 'Connection invalid: -662' (?)

I'm no expert in applescript or automator workflows. This is my first attempt at using these things. So, for now, I prefer the version that works well, although the lists are not sorted.

Many thanks for your help...

Link to comment

koen's certainly right, you can run it using FastScripts, but I don't believe that will get the menu option in Evernote, which I like to have.

If you use Automator, the settings which I know work for my version are below. The same settings should work fine for koen's version.

-- New service

-- Run one application (the script app)

-- receive no input

-- If you select "in Evernote" then the service will appear in the services pull down menu of the Evernote app, and you can assign a keyboard shortcut to it.

It should look like this:

20120223-nhjdqnnjns179tsuts2j7bkc9f.jpg

Link to comment

Good explanation, gtuckerkellogg. Indeed, this will give a Service item for a new note in Evernote. Although I prefer the FastScript solution, I can imagine that people want a menu item for a new note. How do you assing a keyboard shortcut to this Evernote menu item?

Link to comment

At the bottom of the services menu (in any application) there is always a "Services preferences" option. You can also get to this from System Preferences, under "Keyboard". From there you can add keyboard shortcuts to any menu item. You just have to give the name of the menu item. See, for example, that I have the same shortcut defined for "copy note link" and "copy note links". They don't clash because the name of the menu item changes if more than one note is selected.

20120223-bwnc2p6hkrmihc6ubefjnxhtai.jpg

Link to comment

Koen & gtuckerkellogg

The FastScript option works, but I prefer running the script has a Service. The shortcut assignation is has gtuckerkellogg describe.

I'm using the koen version of the 'new note from template'

The step that gtuckerkellogg are what I have done, but I do it again from the scratch, and at the end of the workflow execution I get the same error: 'evernote_new_note_from_templated has detected an error: The conection it is not valid. (-609)'

Link to comment

I've posted a new version of the script with a minor addition: you can now repeat the title of the note in the note's contents. This is done by putting [title] anywhere in your template. I like this, because I want the note's title repeated as the first line of a note (formatted of course). You can find new_note_from_template.scpt v1.1. here.

Link to comment
  • 1 month later...

I would like to have a kind of a formular or a template to put in a new note.

If I want to put in a new Wine into my Wineliste I can just open a formular and there I can say this field is called "Name" the next field is the "producer"-field and so on. Some of them are just text others are pictures.

Is that possible?

Link to comment
  • 3 months later...

I know this might be asking quite a bit, but I was hoping there was a way to integrate what you have done with this article so that I could actually right-click (ctrl+click) a file in Finder and add it to the bottom of an Evernote templated note in a specific notebook.

Man, that would rock my world. I just don't have enough experience with automator or applescript to do this myself and you seem to have figured it all out, so any help would be rewarded with most gracious replies and good karma. And if you're ever in Denver, I'll buy you a beer.

Link to comment
  • 2 years later...
  • Level 5*

I've posted a new version of the script with a minor addition: you can now repeat the title of the note in the note's contents. This is done by putting [title] anywhere in your template. I like this, because I want the note's title repeated as the first line of a note (formatted of course). You can find new_note_from_template.scpt v1.1. here.

 

@Koen:

 

Many thanks for a great script.  I really appreciate you sharing this with us.

 

I realize it is now 3 years later, but I just finally got around to installing your script.

It seems to work as expected, except at the end I get this error:

 

EN-Mac-607-Template.png

 

Any ideas on what is causing this and how to fix?

 

It come up 3 times AFTER the Note is created and shown in a new window.

I just hit cancel (3 times), and everything seems OK.

 

I'm running EN Mac 6.0.7 on Mac OS X 10.9.5 Mavericks.

 

Thanks.

 

=======================

EDIT:  Sat, Mar 28, 2015 at 9:56 PM  CDT

 

I think I may have discovered what is causing these errors/alerts.

I have 3 images at the bottom of my EN template Note.

While a new Note is successfully created from the template Note, it does NOT include these images.

I think the Mac OS is complaining when Evernote tries to display the new Note.

 

@koen, I'm curious as to why you didn't just use the "copy note" function?  I think this might solve the problem.

Link to comment

Hai JMichael,

Glad you enjoy the script. I haven't been working with images in the EN template note, so I didn't know about this behavior.

As to your 'copy note' function: do you mean: R-click on note, and then Copy to Notebook?

Link to comment
  • Level 5*

As to your 'copy note' function: do you mean: R-click on note, and then Copy to Notebook?

 

Yes, exactly.  Can that be done in AppleScript?  I thought that might solve the image URL issue, as well as copy any attachments that are in the template Note.

Link to comment
  • Level 5*

I did some more checking, including a review of the Evernote Applescript dictionary, and it appears that the "copy note to notebook" method is NOT supported in AppleScript.

 

But I did do some manual testing, and perhaps a workaround is to (using AppleScript), export the template note to ENEX, and then import the ENEX file back into the desired Notebook.  I even did a test editing the ENEX file using TextEdit to change the [DateTime] token, and it seemed to work fine after the manual import.

 

Thanks again for a great script.  I learned a lot from it.

Link to comment
  • 8 months later...

Koen, thank you!!! for sharing your applescript, I learnt so much from your work. I am using Alfred to trigger the script, working great: all of the customizing, Best, 

Glad to have been of any help.

Link to comment
  • 1 month later...
  • Level 5*

Thanks for posting your template script @koen
I learned a lot from it

Similar to @JMichaelTX I ran into the embedded images problem and had to remove them from my template.
I also noticed some elements had disappeared (checkboxes).
I'm guessing this is EN's extension to HTML and got lost in the Append HTML

I like having the templates filed in Evernote; its easier to update them.
I'd agree with JM that copy/paste would work, but is not available; and the only solution would be to export/import.
However most people won't need this and would be satisfied with the current process.

Link to comment
  • 1 year later...

Just to confirm, had the same problem as JMichaelTX and as they mentioned already. Its due to images on the template. Don´t really understand about this programming but removing images works just fine. I found FastScripts to be the easiest and most practical way to create the short cut. Thanks a lot.

Link to comment
  • Level 5*
17 hours ago, Yamil Saade said:

Don´t really understand about this programming but removing images works just fine.

My solution was not "removing images"
I changed my script to an export/import in enex format

Link to comment
  • 1 month later...

Archived

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

×
×
  • Create New...