【问题标题】:Apple Tags, Apple Script and Evernote苹果标签、苹果脚本和印象笔记
【发布时间】:2017-12-23 14:23:06
【问题描述】:

我正在使用下面的代码将文件添加到 Evernote,并使用分配给这些文件的 Apple 标签,以便在脚本添加它们时将它们转换为 Evernote 标签。

我使用的脚本运行良好,但有一个问题。我要定位的文件有 2 个标签。

  • 测试标签
  • 测试

然后我运行脚本,这是在 Evernote 中添加到导入文件的内容。

tags added to Evernote

单字标签加细但是2个或更多的标签在标签周围加上引号。我尝试了几种不同的方法来删除它们,但都无济于事,所以我想我会在这里发帖,看看你们这些好人有什么想法。

这是我正在使用的代码。

local targetNotebook, the_tags

set theFile to alias "Users:thomMacBook:Desktop:Inbox:outbox:test.pdf"


set the_tags to paragraphs of (do shell script "mdls -raw -name kMDItemUserTags " & quoted form of POSIX path of theFile & " | sed 's/^[()]$//g' | ruby -ne 'each = $_.strip.end_with?(\",\") ? $_.strip[0...-1] : $_.strip; puts each if each != \"\"'")

set targetNotebook to "Testing"

tell application "Finder"
set createdFileDate to (the creation date of (theFile as alias))
set modFileDate to (the modification date of (theFile as alias))
end tell
tell application "Evernote"
launch
set theItem to create note from file theFile notebook targetNotebook tags the_tags created createdFileDate
set (modification date of theItem) to modFileDate
end tell

提前致谢

【问题讨论】:

    标签: macos tags applescript evernote


    【解决方案1】:

    这对我有用:

        set the_tags to paragraphs of (do shell script
            "mdls -raw -name kMDItemUserTags " & ¬
            quoted form of theFile & ¬
            " | egrep -o '\\w+(\\s*\\w+)+'")
    

    针对我的一个文件对其进行测试,它返回了以下列表:

        {"Green", "Tag1", "This Tag", "Here Is Another Tag", "Tag2"}
    

    我的正则表达式假设标签仅由字母数字和空格组成(我觉得这是一个合理的假设)。如果您有比这更多的异国标签,请发表评论,我会回复您。

    【讨论】:

    • 嗨@CJK 感谢您的回复。尝试了您的解决方案,但出现错误。但是我在“引用形式”之后添加了“POSIX 路径”,它就像一个梦一样工作。非常感谢。多年来一直坚持这一点。这是我最终使用的代码。抱歉,似乎无法将其格式化为代码。将 the_tags 设置为 (do shell script "mdls -raw -name kMDItemUserTags " & POSIX path of theFile & " | egrep -o '\\w+(\\s*\\w+)+'") 的段落, {"test tag", "test", "this is a new tag"},我添加了一个额外的标签来进一步测试它。干杯!
    • 抱歉,是的,我已经将我的变量 theFile 表示为 posix 路径,而忽略了提及。我很高兴你自己解决了这个问题。为布朗尼点干杯!
    【解决方案2】:

    这是一个很好的示例,您可以关注和/或从中获取想法: GET A LIST OF TAGS IN OS X 在 veritrope.com 上。

    【讨论】:

      猜你喜欢
      • 2021-04-20
      • 1970-01-01
      • 2013-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多