Apple标签,Apple脚本和Evernote

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

我正在使用以下代码将文件添加到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
2个回答
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"}

我的正则表达式假设标签只包含字母数字和空格(我认为这是一个合理的假设)。如果你有比这更多的异国情调的标签,请留下评论,我会回复你。


0
投票

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

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