我怎样才能删除的Evernote笔记的最后一行?

问题描述 投票:0回答:2

我想删除每个音符的最后一行的Evernote。这很容易用shell脚本,例如做要使用wc来获得音符的长度,然后用头打印所有线,但最后一个,或SED。但我不能找到一种方法来说明的内容流式传输到外壳。我已经试过这(和许多其他)

do shell script "echo <<<" & noteText

有任何想法吗?

这里是整个脚本

tell application "Evernote"
set noteList to find notes ""
repeat with i from 1 to number of items in noteList
    set this_note to item i of noteList
    set this_note_text to ENML content of this_note
    my removeLastLine(this_note_text)
end repeat
end tell

on removeLastLine(note)
set countCmd to "wc <<< " & note
(* do shell script countCmd *)
set noteText to note as string
log noteText
do shell script "echo <<<" & noteText
(* set newNote to do shell script "head -(size - 1)" *)
end removeLastLine
applescript evernote
2个回答
1
投票

好了,下面是一个使用Evernote的笔记的HTML我的解决方案。 注意:在注任何图像或附件可能会丢失。

鉴于此,当音符的HTML:

<div id="en-note"><div>2019-02-02  21:47 GMT-6</div><div><br/></div><div>REF:  <a href="https://stackoverflow.com/questions/54485617/how-can-i-remove-the-last-line-of-a-note-in-evernote">How can I remove the last line of a note in evernote?</a></div><div><br/></div><div>This is a test.</div><div><br/></div><ol><li>One</li><li>two</li><li>three</li></ol><div><br/></div><div>This is the last line where X&gt;Y, A&lt;B, and a path of /dir1/dir2/file.text.<br/></div></div>

这AppleScript的将删除最后一个用户线。 注:我还在测试正则表达式这一点,所以这应该被认为是BETA / DRAFT版本。但它应该是足够好,让你开始。

请让我们知道这对你的作品,或者您有疑问/问题。

property ptyScriptName : "Remove Last User Text Line from Evernote Note"
property ptyScriptVer : "1.0"
property ptyScriptDate : "2019-02-03"
property ptyScriptAuthor : "JMichaelTX"

use AppleScript version "2.5" -- El Capitan (10.11) or later
use framework "Foundation"
use scripting additions

--- RegEx to Find Last User Text Line ---
## (<div>(?!.+?<div>).+?<\/div>)(<\/div>)$
set reFind to "(<div>(?!.+?<div>).+?<\\/div>)(<\\/div>)$"


tell application "Evernote"
  set noteList to selection
  set oNote to item 1 of noteList
  set bodyHTML to HTML content of oNote

  set bodyNewHTML to my regexChange(reFind, "", bodyHTML)
  set HTML content of oNote to bodyNewHTML
end tell


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

0
投票

这是不是一个解决方案。这是指导/建议,不要在注释行吻合。

你的任务是要复杂得多,它可能会出现。你必须克服两大挑战: (1)卸下用户文本的最后一行(而不是在ENML文本的最后一行) (2)更新现有注ENML。

#1可以克服的。 ENML文本的最后一行包含您不想删除XML标记。它是不一样的,你在Evernote的应用程序查看用户文本的最后一行。下面是一个例子ENML文本,其具有3行文字。最后用户线嵌入在最后ENML线,其中有几个标签。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note><div>2019-02-02  21:47 GMT-6</div><div><br/></div><div>This is a test.</div><div><br/></div><div><ol><li>One</li><li>two</li><li>three</li></ol><div><br/></div></div><div>this is the last line.</div><div><br/></div></en-note>

#2是一个巨大的挑战。您可以通过脚本改变注意HTML,但没有说明ENML。而HTML将不包括嵌入式图像和附件的任何引用。我所看到的唯一的解决方法是编辑埋在~/Library/Application Support/com.evernote.Evernote文件夹(被称为“Evernote的数据库文件夹”)Evernote的数据文件夹中的实际文件。 OTOH,如果你想创建一个使用修改后的文本ENML一个新的注意,那么可以轻松完成。从打开脚本编辑器Evernote的脚本字典,看看什么是可用的。

如果你只是想创建一个新的笔记,请更新您的问题,表示这样的。

如果我有更多的时间,明天,我会进一步检查。


UPDATE 2019年2月3日18:17 GMT-6

所以,现在的OP阐明,他可以只使用HTML工作。因此,这里是由EN注意一个例子HTML

<div id="en-note"><div>2019-02-02  21:47 GMT-6</div><div><br/></div><div>REF:  <a href="https://stackoverflow.com/questions/54485617/how-can-i-remove-the-last-line-of-a-note-in-evernote">How can I remove the last line of a note in evernote?</a></div><div><br/></div><div>This is a test.</div><div><br/></div><ol><li>One</li><li>two</li><li>three</li></ol><div><br/></div><div>this is the last line.</div><div><br/></div></div>

最后一个用户线: This is a test.

我们面临的挑战是,有可能最终</div>之前该行后是其他非文本的东西

现在我工作的正则表达式。如果你们正则表达式大师在那里看到了解决此,请跳。这太糟糕了,我们可以使用Web页面的DOM这一点。这将是比正则表达式更容易。

© www.soinside.com 2019 - 2024. All rights reserved.