Jump to content

AngusSanto

Level 1
  • Posts

    5
  • Joined

  • Last visited

Everything posted by AngusSanto

  1. Hey guys, took me some time but I got it working this morning (I'm Australian). Here's my version of the script that swaps around the title of the note and the first line of the body, based on all the notes you have selected in Evernote. I removed the dialog box from JMichaelTX's code for my own convenience property ptyScriptName : "Set Evernote Note Title to 2nd Body Line Using Plain Text -- TEST" property ptyScriptVer : "BETA 2.0" property ptyScriptDate : "2019-05-19" property ptyScriptAuthor : "JMichaelTX" (* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PURPOSE: • Update Evernote Note Title and Body Using HTML • Set Note Title to 2nd Body Line • Insert Original Note Title at Top of Body RETURNS: Revised Evernote Note REQUIRED: 1. macOS 10.11.6+ 2. Mac Applications • Evernote Mac 6.11.1+ TAGS: @SW.EN @CAT.Notes @CAT.HTML @type.Example REF: The following were used in some way in the writing of this script. 1. 2019-05-17, DTLow, Evernote User Forum Bulk Rename Notes with Script Editor https://discussion.evernote.com/topic/120023-bulk-rename-notes-with-script-editor/?do=findComment&comment=537798 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *) use AppleScript version "2.5" -- El Capitan (10.11) or later use framework "Foundation" -- this may not be required use framework "AppKit" -- this may not be required use scripting additions property LF : linefeed tell application "Evernote" set selectedNotes to (get selection) repeat with oNote in selectedNotes tell oNote set noteTitle to title set noteBodyHTML to HTML content -- Retrieve note contents set noteBodyPtxt to my HTMLDecode(noteBodyHTML) set nbLines to paragraphs of noteBodyPtxt --- Extract the 2nd Line of Text --- -- (ignoring blank lines) set lineCount to 0 repeat with oLine in nbLines if ((contents of oLine) ≠ "") then set lineCount to lineCount + 1 if (lineCount ≥ 1) then set nbLine2 to contents of oLine exit repeat end if end repeat --- Replace Unusual "Â" Character with Space --- set nbLine2Clean to my regexChange("Â", " ", nbLine2) --- REPLACE INVISIBLE CHARS FOUND IN SOME HTML (like OUTLOOK 2011) WITH SPACE --- -- set nbLine2Clean to regexChange("\\x{A0}|\\x{2028}", " ", nbLine2Clean) set bodyLine2 to nbLine2Clean --- Change Note Title to 2nd Body Line --- set title to bodyLine2 --- Insert Original Title at Top of Body --- set HTML content to ("<div>" & noteTitle & "</div>") & noteBodyHTML end tell end repeat end tell --~~~~~~~~~~~~~~~~~ END OF MAIN SCRIPT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ on regexChange(pFindStr, pReplaceStr, pSourceStr) -- @RegEX @Change @Replace @Strings @ASObjC --––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– (* VER: 2.0 2018-07-06 PURPOSE: Change ALL Occurances of pFindStr into pReplaceStr in pSourceStr METHOD: Uses ASObjC RegEx (which is based on ICU Regex) PARAMETERS: • pFindStr | text | RegEx Pattern to Find • pReplaceStr | text | Replace string which • May contain these RegEx MetaChars: \\n, \\r, \\t for linefeed, return, and tab $<CG>, where <CG> is Capture Group number • pSourceStr | text | Source String to be searched RETURNS: Revised String with all changes that were found. AUTHOR: JMichaelTX -- with help from NigelGarvey ## REQUIRES: use framework "Foundation" REF: 1. 2018-07-06, NigelGarvey, Late Night Software Ltd. ASObjC RegEx Change Handler http://forum.latenightsw.com/t/asobjc-regex-change-handler/1395/10 2. ICU RegEx Users Guide http://userguide.icu-project.org/strings/regexp --––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– *) set nsCurApp to current application -- Replace any backslash-n sequences in the replace string with actual character -- set nsReplaceStr to nsCurApp's NSString's stringWithString:pReplaceStr set nsReplaceStr to nsReplaceStr's stringByReplacingOccurrencesOfString:"\\n" withString:(linefeed) set nsReplaceStr to nsReplaceStr's stringByReplacingOccurrencesOfString:"\\r" withString:(return) set nsReplaceStr to nsReplaceStr's stringByReplacingOccurrencesOfString:"\\t" withString:(tab) set nsSourceStr to nsCurApp's NSString's stringWithString:pSourceStr set nsSourceStr to (nsSourceStr's stringByReplacingOccurrencesOfString:pFindStr withString:nsReplaceStr options:(nsCurApp's NSRegularExpressionSearch) range:{0, nsSourceStr's |length|()}) return nsSourceStr as text end regexChange --~~~~~~~~~~~~~~~~~~~~ END of Handler ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ on HTMLDecode(HTMLString) -- @HTML @Strings @Decode @Convert @Text @PlainText @ASObjC -------------------------------------------------------------------------------------- (* From: Shane Stanley <sstanley@myriad-com.com.au> Date: Thu, Jun 16, 2016 at 8:56 PM To: "ASUL (AppleScript)" <applescript-users@lists.apple.com> Subject: Re: Convert HTML Text to Plain Text -- ASObjC handler is 2.03 X as fast as Shell Handler *) -- make it an NSString set theString to current application's NSString's stringWithString:HTMLString -- get raw data set theData to theString's dataUsingEncoding:(current application's NSUTF8StringEncoding) -- convert to attributed string set attStr to current application's NSAttributedString's alloc()'s initWithHTML:theData documentAttributes:(missing value) -- extract just the text set plainText to attStr's |string|() as text --- REPLACE INVISIBLE CHARS FROM OUTLOOK WITH SPACE --- -- set plainText to regexChange("\\x{A0}|\\x{2028}", " ", plainText) return plainText end HTMLDecode
  2. @JMichaelTX Sorry for the delay, been a long day, just trying to work with the script now - It seems to work as I originally described but I've realised I made a mistake in the way I described what I was looking to do - rather than the second line of the body I need to make the title the first line of the body - I was getting confused and assumed that the title was already the first line. The script is a bit beyond my level so I haven't been able to figure out how to change it to apply to the first line rather than the second, could you help with this? Other than that the script works, although at the moment it only automatically applies to the last created note for me - is there a way to get it to apply to all of the notes in a specific folder or with a specific tag?
  3. @JMichaelTX Thanks so much - going to test it out today and I’ll let you know how it goes
  4. @JMichaelTX @DTLow Thanks so much for your responses - I would love to see your solution JMichaelTX as that sounds like exactly what I need and I haven’t had time to look at the simple option 1 solution myself yet - if you have space would love to see your script
  5. Hi, I'm looking for some help on quite a specific project. I'm new to using Script Editor on Mac, but have successfully used it to move all of my notes from Apple Notes to Evernote. However, now I would like to bulk rename all of the notes in this way: I would like to move the current title (the text on the first line of the note) to become the second line of each note, and move the second line of each note to become the title. Is this possible? I found this script to bulk rename notes but it doesn't have this level of functionality (https://gist.github.com/brandonpittman/5994734)
×
×
  • Create New...