Jump to content

Recommended Posts

Hello. First time posting.

So I have been teaching myself web design & development, and using Evernote to keep notes on various languages and frameworks. These notes have, of course, code snippets, mostly that I copy in or type out by hand (for example, as I watch a video on Code School). These are interspersed with my explanations and comments. So I am typing my note in the default font, Helvetica Neue, and then going back through and changing the code snippets to Courier New. I know I can go and put my snippets into some code formatter web app and paste them back in, but for my purposes all I really want is for snippets to be a different font. And I want to avoid the hassle of selecting the snippet and going through the font dropdown every time.

I was wondering if there was a way to do this. I have been fiddling with AppleScript, trying to make a Service that I could then bind to a keyboard shortcut, but Evernote doesn't seem to allow access to the actual content of notes from AppleScript. Right now I'm trying to save the note HTML content to a variable and then add a font tag to lines that start with a certain character, but I was just introduced to AppleScript today so I don't really know what I'm doing.

Here's the lame attempt I have so far:

property noteHtml : ""
property addOn : "<br><br><hr><br><br>"

tell application "Evernote"
	activate
	set note1 to selection
	set noteHtml to (HTML content of note1)
	set addString to "<br>"
	if {noteHtml starts with "<p>"} then
		set editHtml to ?
		set noteHtml to editHtml
	end if
end tell

Can anyone offer any tips or a solution? Thanks.

Share this post


Link to post

Well, after some more digging in the forums, I have found a workaround (only works for OSX). In System Preferences -> Keyboard -> Shortcuts -> App Shortcuts, you just make a new shortcut with a title = font name, and set the key combo. Good enough for me, but please if you have something better don't hesitate to post!

Share this post


Link to post
19 hours ago, grumpyclam said:

all I really want is for snippets to be a different font

The latest version of EN Mac has a new Code Block feature which should do just what you are asking for.
See EN Mac 6.5 Update -- Released 

You will need to enable this feature in the EN Mac Preferences.

  • Like 1

Share this post


Link to post
9 minutes ago, JMichaelTX said:

You will need to enable this feature in the EN Mac Preferences.

I don't see anything related to a Code Block feature anywhere in the Preferences. Not a Premium feature, is it?

Share this post


Link to post
20 hours ago, grumpyclam said:

Well, after some more digging in the forums, I have found a workaround (only works for OSX). In System Preferences -> Keyboard -> Shortcuts -> App Shortcuts, you just make a new shortcut with a title = font name, and set the key combo. Good enough for me, but please if you have something better don't hesitate to post!

That sounds like a better solution than applescript to mess with the html code.
You could also look at the keyboard macro-shortcut apps (example Keyboard Maestro)
I don't use them but I understand they will allow you to set up a series of keystrokes to simplify the font assignment.

Share this post


Link to post

By converting the paragraph to string you are inherently stripping all the formatting data.Instead, you should reference the data as text.Text retains formatting and style data and will do what you want. Replace every instance of 'as string' in your script with 'as text' and you should be set.

 

Universal Access System Preference pane.

 

set theReplacements to 

    {"0mg ", "0 mg "}, ¬

    {"5mg ", "5 mg "}, ¬

    {"  ", " "} ¬

        }

 

tell application "Pages" to activate

tell application "System Events" to tell process "Pages"

    keystroke "f" using command down

    repeat until exists window "Find & Replace"

    end repeat

    tell window "Find & Replace"

        click radio button "Simple" of tab group 1

        repeat with thisReplacement in theReplacements

            set {X, Y} to thisReplacement

            keystroke X

            keystroke tab

            keystroke Y

            keystroke tab

            click button "Replace All" of tab group 1

        end repeat

        click button 1

    end tell

end tell

 

The script has been tested under OS X 10.8.1.

 

 

 

 

hadoop training in chennai | informatica training in chennai

Edited by richardsonkane75
modify

Share this post


Link to post
23 hours ago, richardsonkane75 said:

tell application "Pages" to activate

Thanks for sharing your script.

Since your script is working with the Mac app Pages, how do you suggest it be used with Evernote?
Remember that EN Mac does NOT have a "Find & Replace" menu/action/command.

Share this post


Link to post

FWIW, I was looking into using Applescript to format single lines of text  for title headers in notes. I just got fed up with digging around in Font dialogs when all I wanted was for this line to be H2, or something. It uses System events to select and grab the current line into the clpboard then calls the textutil standalone to do the formatting, pasting the result back into the note. It's kludgy but functional. The most significant annoyance is that it requires 2 1 second sleeps. I see no way around that.

For myself I have it stored as a set of Keyboard Maestro Macros for varying sizes, triggered by text strings #, ##, ###, ###, etc as per Markdown - I have shortcut keys coming out my ears and this is easy to remember.

 

delay 1 -- necessary
tell application "System Events"

    keystroke (ASCII character 28) using {command down}
    keystroke (ASCII character 29) using {command down, shift down}

    keystroke "c" using {command down}

end tell

delay 1 -- necessary

-- set fontsize to 28
do shell script "pbpaste | textutil -stdin -stdout -convert rtf -fontsize 28 | pbcopy"
tell application "System Events" to keystroke "v" using command down

Enjoy

Share this post


Link to post
3 hours ago, kimaldis said:

I just got fed up with digging around in Font dialogs

fwiw   On the Macs you can assign a keyboard shortcut to any menu item (including fonts and sizes).  The style update could be implemented without calling TextUtil

Share this post


Link to post
3 hours ago, DTLow said:

On the Macs you can assign a keyboard shortcut to any menu item (including fonts and sizes).  The style update could be implemented without calling TextUtil

I'd be interested in seeing how you would do this.  Neither the Font popup nor the Font Size popup are in the Evernote menu.  How would you assign a shortcut to a specific font and size?

Share this post


Link to post
43 minutes ago, JMichaelTX said:

How would you assign a shortcut to a specific font and size?

These are the font/size controls being used 593eee2822344_ScreenShot2017-06-12at12_38_55.png.83cbefd91a59117205dec511e0fc9501.png

Shortcuts assigned in system preferences                          And they are functional

593eeb63279e4_ScreenShot2017-06-12at12_21_14.png.452f5701b44279e9420f0713eaef89e5.png               593eef15dabd3_ScreenShot2017-06-12at12_43_29.png.3dea03d2b1102c54e94ac1173ac0332b.png   593eea29236b7_ScreenShot2017-06-12at12_22_42.png.9f50e3a3a7820aeef82ba136afb55268.png

 

 

The AppleScript code is
    tell application "System Events" to keystroke "h" using {command down, option down, control down}
    tell
application "System Events" to keystroke "1" using {command down, option down, control down}

  • Like 1

Share this post


Link to post
On 3/7/2016 at 3:56 AM, grumpyclam said:

So I am typing my note in the default font, Helvetica Neue, and then going back through and changing the code snippets to Courier New.
. . .
but for my purposes all I really want is for snippets to be a different font. And I want to avoid the hassle of selecting the snippet and going through the font dropdown every time.

I was wondering if there was a way to do this. I have been fiddling with AppleScript . . .

You will still have to select the code snippet in Evernote, but you can use an AppleScript to automatically apply a font and size to the snippet.
See this script I have just posted on a GitHub Gist:  Set Evernote Mac Font and Text Size using AppleScript 

If you store the script in the standard Scripts folder, you can access it  from the Apple menu bar.  And/or you can use a tool like FastScripts (recommended) to assign a shortcut to the script.

If you have any comments, questions, or issues about this script, please post them here so I will be notified, and all can see.

Share this post


Link to post
17 hours ago, DTLow said:

fwiw   On the Macs you can assign a keyboard shortcut to any menu item (including fonts and sizes).  The style update could be implemented without calling TextUtil

The script selects the current line for you; that you can't do from a menu.

Share this post


Link to post
3 hours ago, kimaldis said:

The script selects the current line for you; that you can't do from a menu.

For selecting a line; the command-arrow keystrokes work well, although I'm more inclined to use mouse clicks
I see no need for a menu item

Share this post


Link to post
2 hours ago, DTLow said:

For selecting a line; the command-arrow keystrokes work well, although I'm more inclined to use mouse clicks

But the script saves you that step. It's quicker and why do it if you don't need to.

Share this post


Link to post
2 hours ago, kimaldis said:

But the script saves you that step. It's quicker and why do it if you don't need to.

I have no issue with the script selecting the line; it's an elegant solution
My origional response related to calling TextUtil to apply the font/size style; instead,  keystrokes can be used

  • Like 1

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...