[Share] Replace Tag #113
Replies: 6 comments
-
I would like to have a script which does the following for a collection
Could this be done? |
Beta Was this translation helpful? Give feedback.
-
Great!!! |
Beta Was this translation helpful? Give feedback.
-
Thanks for sharing! Here I did some modification to better adopt my workflow by adding matching rules with desired tag group and item with empty tag. For anyone who may interested about it: // Replace tags with a matching pattern from a group, even for untagged items
// @author windingwind
// @enhanced by gitnapp
// @link https://github.com/windingwind/zotero-tag/discussions/113
// @usage Shortcut
if (!item) {
return "[Replace Tags] item is empty";
}
// Define the array of tags to match
const tagsToMatch = ["/done", "/pending", "/unread", "/reading"];
// The tag to add after matching and replacing
const tagToAdd = "/tocheck";
// Check if the item is untagged or if it contains any of the tags to match
if (item.getTags().length === 0 || item.getTags().some(obj => tagsToMatch.includes(obj.tag))) {
// If the item is untagged or contains a matching tag, remove the matching tags (if any)
item.getTags().forEach(tagObj => {
if (tagsToMatch.includes(tagObj.tag)) {
item.removeTag(tagObj.tag);
}
});
// Add the new tag
item.addTag(tagToAdd);
// Return a message indicating the replacement
// If the item was untagged, mention that in the message
const untaggedMessage = item.getTags().length === 0 ? " for an untagged item" : "";
return `[Replace Tags] replaced matching tags [${tagsToMatch.join(', ')}] with ${tagToAdd} on ${item.getField("title")}${untaggedMessage}`;
}
return `[Replace Tags] no matching tag found for replacement on ${item.getField("title")}`; |
Beta Was this translation helpful? Give feedback.
-
This one is similar as well, marks all of the selected items as
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I also have a similar script. A number of journals add asterisks to keywords (tags) and they are annoying and ruin my workflow. This script simply deletes the asterisks. I just search for * in all fields and tags, save the search, select all in the saved search, and run the script: EventNone OperationScript Data// Bulk remove a character from an array of tags
// @author windingwind
// @modified by geogrrl
// @link https://github.com/windingwind/zotero-tag/discussions/113
// @usage Shortcut
if (!item) {
return "[Remove Asterisks] item is empty";
}
const tags = item.getTags();
const updatedTags = tags.map(tagObj => {
return { tag: tagObj.tag.replace(/\*/g, '') };
}).filter(tagObj => tagObj.tag !== '');
item.setTags(updatedTags);
return `[Remove Asterisks] asterisks removed from tags on ${item.getField("title")}`; |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
Replace tag.
Please replace the following lines in the action script before applying it:
Show lines to edit
Action Settings
Operation: Script
Data:
Beta Was this translation helpful? Give feedback.
All reactions