[Share] Auto-tag when keyword detected in title #119
Replies: 8 comments 22 replies
-
Thanks, this feature is very useful. How can I use multiple keywords and tags in only one script? More specifically, if the title contains keywords A or B, add tags named C and D. |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
以下代码可以同时检测标题或摘要中是否含有某个字段,并返回相应标签: // Auto-tag based on specific keywords in the title and abstract
// @author windingwind
// @link https://github.com/windingwind/zotero-actions-tags/discussions/119
// @usage Replace the `KEYWORDS_AND_TAGS` array with your own keywords and corresponding tags.
// @see https://github.com/windingwind/zotero-actions-tags/issues/77
// @see https://github.com/windingwind/zotero-actions-tags/issues/85
if (!item) {
return "[Conditional Tag] item is empty";
}
const KEYWORDS_AND_TAGS = [
{ keyword: "FIELD_A", tag: "TAG_B" },
{ keyword: "FIELD_C", tag: "TAG_D" },
// You can add more keyword-tag pairs as needed
];
const title = item.getField("title");
const abstract = item.getField("abstract");
let tagged = false;
for (const pair of KEYWORDS_AND_TAGS) {
const { keyword, tag } = pair;
if (title.includes(keyword) || (abstract && abstract.includes(keyword))) {
item.addTag(tag, 1);
tagged = true;
}
}
if (tagged) {
return `[Conditional Tag] item "${title}" has been tagged based on keywords in title or abstract.`;
} else {
return `[Conditional Tag] item "${title}" does not match any keywords in the list in title or abstract.`;
} |
Beta Was this translation helpful? Give feedback.
-
感谢大佬回答,不过运行后没有成功添加标签 if (!item) { const KEYWORDS_AND_TAGS = [ const title = item.getField("title"); for (const pair of KEYWORDS_AND_TAGS) { if (tagged) { |
Beta Was this translation helpful? Give feedback.
-
oh I see so this is also only for Z7 |
Beta Was this translation helpful? Give feedback.
-
Hello, |
Beta Was this translation helpful? Give feedback.
-
我感觉是需要脚本维护一个 tags 库,我在想能不能这样:
|
Beta Was this translation helpful? Give feedback.
-
使用这个脚本添加了一堆tags,请问作者有没有批量删除它们的脚本。。。(好像zutilo有此功能) |
Beta Was this translation helpful? Give feedback.
-
Description
Auto-tag when keyword detected in title. See #77 #85.
Action Settings
Event: Create Item
Type: Script
Data:
Beta Was this translation helpful? Give feedback.
All reactions