grumpyclam 0 Posted March 7, 2016 Share Posted March 7, 2016 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. Link to comment
grumpyclam 0 Posted March 7, 2016 Author Share Posted March 7, 2016 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! Link to comment
Level 5* JMichaelTX 4,118 Posted March 8, 2016 Level 5* Share Posted March 8, 2016 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. 1 Link to comment
grumpyclam 0 Posted March 8, 2016 Author Share Posted March 8, 2016 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? Link to comment
grumpyclam 0 Posted March 8, 2016 Author Share Posted March 8, 2016 Ah nevermind, I see it's only available on the direct download version. Thanks! Link to comment
Level 5* DTLow 5,744 Posted March 8, 2016 Level 5* Share Posted March 8, 2016 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. Link to comment
Frank.dg 1,385 Posted March 8, 2016 Share Posted March 8, 2016 Looks like there are 2 native solutions for Mac, then. Additionally, on the Mac (desktop) Beta one can use Markdown formatting - including wrapping your code in `backticks`... which will automatically be converted to a code block. https://discussion.evernote.com/topic/88677-evernote-for-mac-62-beta-1-released/ Link to comment
richardsonkane75 0 Posted March 10, 2016 Share Posted March 10, 2016 (edited) 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 March 10, 2016 by richardsonkane75 modify Link to comment
Level 5* JMichaelTX 4,118 Posted March 11, 2016 Level 5* Share Posted March 11, 2016 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. Link to comment
kimaldis 1 Posted June 12, 2017 Share Posted June 12, 2017 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 Link to comment
Level 5* DTLow 5,744 Posted June 12, 2017 Level 5* Share Posted June 12, 2017 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 Link to comment
Level 5* JMichaelTX 4,118 Posted June 12, 2017 Level 5* Share Posted June 12, 2017 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? Link to comment
Level 5* DTLow 5,744 Posted June 12, 2017 Level 5* Share Posted June 12, 2017 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 Shortcuts assigned in system preferences And they are functional 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} 1 Link to comment
Level 5* JMichaelTX 4,118 Posted June 13, 2017 Level 5* Share Posted June 13, 2017 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. Link to comment
kimaldis 1 Posted June 13, 2017 Share Posted June 13, 2017 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. Link to comment
Level 5* DTLow 5,744 Posted June 13, 2017 Level 5* Share Posted June 13, 2017 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 Link to comment
kimaldis 1 Posted June 13, 2017 Share Posted June 13, 2017 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. Link to comment
Level 5* DTLow 5,744 Posted June 13, 2017 Level 5* Share Posted June 13, 2017 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 1 Link to comment
kimaldis 1 Posted January 11, 2020 Share Posted January 11, 2020 OK, here's my take on this: * System prefs, shortcuts to assign shortcuts to font size (4 - 14,18,24,36) and font (1, Arial) - thanks @DTLow for that, I assumed it only applied to top menubar items * BetterTouchtool to put buttons in the touch bar for Headings 1,2,3 and normal which calll applescripts when pressed. Heading scripts select the line then send shortcut keystrokes to apply font and size to the line from the menu. Normal selects the paragraph rather than a line. Better touch tool and the touch bar because I can't be. bothered to remember the shortcuts, which can be obscure because looking for ones that aren't taken. ( I used <ctrl>1,2,3,4,5 ) tell application "System Events" key code 123 using {command down} key code 124 using {command down, shift down} keystroke "1" using {control down} -- H1 (36) delay 0.1 keystroke "5" using {control down} -- Arial end tell tell application "System Events" key code 126 using {option down} -- paragraph select key code 125 using {option down, shift down} keystroke "4" using {control down} -- size 14 delay 0.1 keystroke "5" using {control down} - Arial end tell I've struggled for ever to get something close to OneNote's rather slick text formatting workflow and, for me, this is about as good as it needs to be. I can literally place the cursor, hit a key and the line or paragraph is transformed instantly The advantage of BetterTouchTool wrapping it is a) no shortcut to remember and b) you get to combine both font and font size changes in one hit. If you don't have a tuch bar, assign the scripts to key presses or sequences. I didn't really do much, it's just a gathering of what's gone before here, so thanks to those that went before. Next battle, proper tag hierarchies and infinite notebook nesting depth. Forward!! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now