Jump to content

HOWTO: Create hotkeys to set predefined font and H1, H2, H3 styles


Recommended Posts

With this script you can press Control + Shift + 1 through 9, and it will set user defined custom styles to your selected note text.

If I haven't made any parts of this tutorial easy to follow, please let me know.

I use a lot of AutoHotKey scripts to automate Evernote, and I thought I'd share some of them. AutoHotKey is an incredible bit of (free) software that can automate anything that you can physically do with your computer. If you don't have a copy, you'll need to install it for this to work. To make sure your script is running every time you start Windows, do this.

I work on a lot of documentation in Evernote, and I wanted a way to easily set standard heading and paragraph styles. I created a little script that let's me send Ctrl + Shift + 1 through 9 to set various styles that I have defined. Here's the script, and then I'll explain how it works:

#IfWinActive, ahk_exe evernote.exe
    ^1::SetFontStyle("bold", 18)
    ^2::SetFontStyle("italic", 16)
    ^3::SetFontStyle("bold", 14)
    ^Space::SetFontStyle("regular", 12)
#IfWinActive

SetFontStyle(weight, size) {
    currentSendMode := A_SendMode ; Get the current Send Mode
    SendMode Event ; Event mode works better in the Font dialog
    Send {Home}+{End} ; Select the current line
    Send ^d ; Open the Font dialog box
    WinWait Font, , 5
    Sleep 200
    Send !y%weight% ; Style
    Send !s%size% ; Size
    Send {Enter}
    SendMode %currentSendMode%
}

 
The first hotkey Control + Shift + 1 sets the font to be 18pt bold. The second hotkey Control + Shift + 2 sets the font to be 16pt italic.
 
If you want to change the settings to suit yourself, just edit the lines in the middle that are marked. You can make yourself as many hotkeys as you like, here's the format for doing them: https://autohotkey.com/docs/Hotkeys.htm
 
Here's the explanation:
 
First off is the #IfWinActive command. This means the hotkeys will only be active if the Evernote window is in the foreground.
The next lines call a function named SetFontStyle when you press a hotkey. "^+1::" means if Control (^), Shift (+) and the number 1 key are pressed at the same time, it knows to run the function with a font style of "bold" and a font size of "18".
 
In the SetFontStyle function, "Send ^d" sends the keystroke Control + D, to bring up the font dialog box. We then wait for the Font dialog window to pop up.
Next line tabs to the font style part of the box and sets it as bold, then tabs to the font size and sets it as 18 points. We then hit enter and exit the dialog.
 
Simple! Hope this helps someone. :)
 
---
 
If you have another language than English, please follow these instructions to make it work with your language:

You'll need to modify the name of the Font dialog. Change the word "Font" to be whatever your one is:

WinWait Font, , 5

And then on these two lines:

Send !y%weight% ; Style
Send !s%size% ; Size    

You'll need to make sure the keyboard shortcuts still work in your language. Here is my Font dialog. Notice how there is an underline under the 'y' of 'Style', and under the 'S' of 'Size'. That is the shortcut key.

ScreenClip [8].png

Have a look in your one and find out what letter it is, and then change the two lines of the script to match. I've highlighted in red the two letters in the snippet of code above.

Save it and reload, and it should work for you!

Link to comment
  • 2 weeks later...

Alliance,

 

Thanks a lot for this tip! It sure help me :)

 

This is definatelly something I was looking for.

 

We say in your post that you "use a lot of AutoHotKey scripts to automate Evernote". Since I'm looking for this kind of things, I ask if you please can give/share more examples.

 

Thanks in advance.

Link to comment

As I was tunning your script to my use I notice it only work in the Evernote main Window.

 

Do you know how can I make also work when I open a single note as a full window?

 

Thanks in advance.

Change the first line to this and it should work for both the main EN window and the single note window:
GroupAdd, EN_Windows, ahk_class ENMainFrameGroupAdd, EN_Windows, ahk_class ENSingleNoteView#IfWinActive, ahk_group EN_Windows
Link to comment

Alliance,

 

Thanks a lot for this tip! It sure help me :)

 

This is definatelly something I was looking for.

 

We say in your post that you "use a lot of AutoHotKey scripts to automate Evernote". Since I'm looking for this kind of things, I ask if you please can give/share more examples.

 

Thanks in advance.

 

I use a lot of scripts that would only make sense for me and they way I use Evernote, but let me know what you're looking for and I'd probably be able to make one for you.

Link to comment

As I was tunning your script to my use I notice it only work in the Evernote main Window.

 

Do you know how can I make also work when I open a single note as a full window?

 

Thanks in advance.

Change the first line to this and it should work for both the main EN window and the single note window:
GroupAdd, EN_Windows, ahk_class ENMainFrameGroupAdd, EN_Windows, ahk_class ENSingleNoteView#IfWinActive, ahk_group EN_Windows

 

Thanks Scott, I've updated my post.

Link to comment

Just to say thanks for yours quick and helpfull answers.

 

 

@Qot:

Regarding the bellow comment.

Alliance,

 

Thanks a lot for this tip! It sure help me :)

 

This is definatelly something I was looking for.

 

We say in your post that you "use a lot of AutoHotKey scripts to automate Evernote". Since I'm looking for this kind of things, I ask if you please can give/share more examples.

 

Thanks in advance.

 

I use a lot of scripts that would only make sense for me and they way I use Evernote, but let me know what you're looking for and I'd probably be able to make one for you.

 

For now I can't specify in detail any need. I'm more interested and see others pratices and try to understand what can be good to me use.

 

So I will continue searching.

 

Thanks for all.

Link to comment
  • 6 months later...
  • 4 months later...
  • 4 weeks later...

Hi Johnny,

 

Regarding your question:

 

Does anyone know a way to use hotkeys for headings on Mac?

 

The only thing I can say, is that Autohotkey is a Windows Software, and so can't be used in Mac OS*.

 

Maybe you should work in Google and in this Forum, if there is any similar way to create headings in Evernote in the Mac OS client.

 

Regards,

Urbano

 

* As far, as I know.

Link to comment
  • 1 year later...
On 3/7/2014 at 6:48 PM, JohnnyJohnster said:

Does anyone know a way to use hotkeys for headings on Mac?

Here are 2 possible solutions for Mac users using PhraseExpress (Mac and Windows): 

I haven't tried out Keyboard Maestro yet

Link to comment
  • 4 months later...
On 7/25/2016 at 3:15 AM, Arcanjo said:

It's 2016 and Evernote doesn't have this feature implemented natively yet. I'm really glad that I found this script.

Massive thank you to you qot! Seriously!

Thanks for the kind words Arcanjo!

I've gone and updated the main script to make it easier for people to add their own styles, have a look.

Link to comment

autohokey is great (I am using it also for evernote (Vim-like controls). Thank you for you script qot.

However this is really a shame that we still need an external software to be able to work efficiently in Evernote. We are talking about basic content formatting (for years now...).. :x. 

Link to comment
10 hours ago, xaa said:

autohokey is great (I am using it also for evernote (Vim-like controls). Thank you for you script qot.

However this is really a shame that we still need an external software to be able to work efficiently in Evernote. We are talking about basic content formatting (for years now...).. :x. 

I totally agree, but I wish more people would give this script a go. I had almost quit using Evernote in frustration until I got this going.

I actually use a great bit of software for journaling called "The Journal" by DavidRM, and it supports styles perfectly. I can't understand why Evernote can't do the same....

Link to comment

thank you @qot.  The script wasn't working here (win10).

- added a  coma after IfWinActive.
- added send {tab} line between style & size to switch to the size field.
- (!'ve commented the WinWait line as it seems ok without (at least here..) .

#IfWinActive,  ahk_exe evernote.exe
    ^1::SetFontStyle("bold", 18)
    ^2::SetFontStyle("italic", 16)
    ^3::SetFontStyle("bold", 14)
    ^Space::SetFontStyle("regular", 12)
#IfWinActive

SetFontStyle(weight, size) {
    currentSendMode := A_SendMode ; Get the current Send Mode
    SendMode Event ; Event mode works better in the Font dialog
    Send {Home}+{End} ; Select the current line
    Send ^d ; Open the Font dialog box
    ;WinWait Font, ,5 
    Sleep 200
    Send !y%weight% ; Style
    Send {tab}
    Send !s%size% ; Size
    Send {Enter}
    SendMode %currentSendMode%
}

 

Link to comment
2 hours ago, xaa said:

thank you @qot.  The script wasn't working here (win10).

Thanks for the feedback. I'm using Win10 as well (and 7), so must be some other trickery going on.

I've added the comma into the OP. The {tab} should be unneccesary as we're sending alt+y and alt+s to switch between those two fields. Was it failing to switch?

Link to comment
  • Level 5*

Thank you @qot. Very helpful, and interesting as I needed to learn some PERL stuff several years ago. Key things for me would be to look at making the font consistent throughout the note, and then to modify multi-line headings - selecting them at present only goes to the end of the first or last line (I am not sure which because I haven't tested it enough) and misses the other line(s).

Ultimately, some of the web sites I extract notes from seem to have weird HTML codes that create extra space before headings and text paragraphs. If I could find a way of removing these at the same time I modify the headings I would be very happy.

Link to comment
4 minutes ago, FactMan said:

Thank you @qot. Very helpful, and interesting as I needed to learn some PERL stuff several years ago. Key things for me would be to look at making the font consistent throughout the note, and then to modify multi-line headings - selecting them at present only goes to the end of the first or last line (I am not sure which because I haven't tested it enough) and misses the other line(s).

Ultimately, some of the web sites I extract notes from seem to have weird HTML codes that create extra space before headings and text paragraphs. If I could find a way of removing these at the same time I modify the headings I would be very happy.

For your use case (multi-line), you could delete the line in the script that says "Send {Home}+{End} ; Select the current line ", and just select the text yourself before pushing the hotkey.

I can't think of any way to programmatically determine whether a heading is one line or multi-line.

Link to comment
  • Level 5*

Thanks for the quick response. I will explore in more detail, but in a regular text file you would be looking for an end of line or end of paragraph character. I recognize that may not apply here - it may be that the underlying text is different... How much of the coding is unique to Endnote? For example, I discovered that it is not easy to make a heading bold italics...

Link to comment

Little downside: This nice script only works on English Evernote instances ...

I still don't get it: There are so many great improvements in the evernote client (like "remember view settings"), but things like this are still lacking.

Markdown FTW!

Link to comment
12 hours ago, andreb said:

Little downside: This nice script only works on English Evernote instances ...

I still don't get it: There are so many great improvements in the evernote client (like "remember view settings"), but things like this are still lacking.

Markdown FTW!

You should be able to easily change it to work with any language.

You'll need to modify the name of the Font dialog. Change the word "Font" to be whatever your one is:

WinWait Font, , 5

And then on these two lines:

Send !y%weight% ; Style
Send !s%size% ; Size    

You'll need to make sure the keyboard shortcuts still work in your language. Here is my Font dialog. Notice how there is an underline under the 'y' of 'Style', and under the 'S' of 'Size'. That is the shortcut key.

ScreenClip [8].png

Have a look in your one and find out what letter it is, and then change the two lines of the script to match. I've highlighted in red the two letters in the snippet of code above.

Save it and reload, and it should work for you!

Link to comment
10 hours ago, qot said:

Save it and reload, and it should work for you!

Thanks for your effort qot; my posting was rather to express my frustration with Evernote. It shouldn't be a normal user's task to implement stuff like this ...

Link to comment

I also really hope that Evernote fix this fast in their next versions:

  • formatting and bookmarks, if possible in the next one.

Although I'm a Pro user, I'm seeing my self using more and more Microsoft Onenote, because of these capabilities.

Evernote excel in information capture. Specially in web information, but must evolve in personal notes creation and editing.

Please change this quickly Evernote, to justify your value\price.

 

Link to comment
  • 2 months later...
On 11/17/2016 at 5:21 PM, HotChips said:

Your script seems to be using ctrl1, NOT ctrl+1. Otherwise works as described for me on Windows 10. Thanks

Yes, "Ctrl + 1" means press Control and 1. The plus sign means "in addition to".

Link to comment
  • 1 year later...

I like how quick this was to setup and edit.  The only drawback at the moment is that the colour selection in the font dialog is limited compared to the colour button on the toolbar.  [I'll mess around with that, or the Paraphrase workaround, later... this works well enough for the moment. The paraphrase/word solution might solve the colour highlighting as well

 

And yes... all these workaround should be completely unnecessary.

Link to comment

FWIW, My version of the script... inlines the function, but sets the font.  CTRL+SHIFT+0  is the "regular" font.  [Might switch to the Paraphrase style solution though, as I think I can get colour highlighting working with that approach.]

 

Anyone else have interesting versions of this script to share?

 

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

GroupAdd, EN_Windows, ahk_class ENMainFrame
GroupAdd, EN_Windows, ahk_class ENSingleNoteView
#IfWinActive, ahk_group EN_Windows

;; Evernote Styles workaround
; Highlights current line, then opens font dialog, and sets properties
; Limitations: 
; + Colour setting switches between blue/black so needs work
;   + although right now this is beneficial as it allows switching between blue and black, lol (but I'll take that out)
; + Colour selection is limited (the toolbar offers more colours)
; TODO: Paraphrase solution might offer more formatting choices, such as Colour Highlights

; CTRL+SHIFT+1 Heading 1
^+1::
Send {Home}+{End}^d
WinWait Font
Send Tahoma{Tab}Bold{Tab}16{Tab 3}B{Enter}
return

; CTRL+SHIFT+1 Heading 2
^+2::
Send {Home}+{End}^d
WinWait Font
Send Tahoma{Tab}Bold{Tab}14{Tab 3}B{Enter}
return

; CTRL+SHIFT+1 Heading 3
^+3::
Send {Home}+{End}^d
WinWait Font
Send Tahoma{Tab}Bold{Tab}12{Tab 3}B{Enter}
return

; CTRL+SHIFT+0 back to "regular" text when undo doesn't work (resets the colour, so run twice to get black)
; doesn't clear all attributes though... just sets it to 9pt, Regular, Black/Blue
^+0::
Send {Home}+{End}^d
WinWait Font
Send Tahoma{Tab}Regular{Tab}9{Tab 3}B{Enter}
return

 

Link to comment

Archived

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

×
×
  • Create New...