Skip to content

Instantly share code, notes, and snippets.

@avernet
Created March 4, 2026 21:30
Show Gist options
  • Select an option

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

Select an option

Save avernet/28a781331c2c417a80157a110ea37a23 to your computer and use it in GitHub Desktop.
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 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) {
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