Skip to content

Instantly share code, notes, and snippets.

@avernet
Last active March 4, 2026 21:28
Show Gist options
  • Select an option

  • Save avernet/ee26f16596bd8404f675dd0485b7e647 to your computer and use it in GitHub Desktop.

Select an option

Save avernet/ee26f16596bd8404f675dd0485b7e647 to your computer and use it in GitHub Desktop.
Finds all descendants of the current item that are completed and contain the string "πŸ‘‰β–‘", then uncomplete them and replace the string with "β– "
const TARGET = "πŸ‘‰β–‘";
const REPLACEMENT = "β– ";
function getAllDescendants(item) {
const results = [];
for (const child of item.getChildren()) {
results.push(child);
results.push(...getAllDescendants(child));
}
return results;
}
function itemNeedsUpdate(item) {
const containsTarget = item.getName().includes(TARGET) || item.getNote().includes(TARGET);
return item.isCompleted() && containsTarget && !item.isReadOnly();
}
const descendants = getAllDescendants(WF.currentItem());
const itemsToUpdate = descendants.filter(itemNeedsUpdate);
if (itemsToUpdate.length === 0) {
WF.showMessage("No matching items found.", false);
} else {
WF.editGroup(() => {
for (const item of itemsToUpdate) {
WF.completeItem(item);
if (item.getName().includes(TARGET))
WF.setItemName(item, item.getName().replaceAll(TARGET, REPLACEMENT));
}
});
WF.showMessage(`Updated ${itemsToUpdate.length} item(s).`);
setTimeout(WF.hideMessage, 5000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment