Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

How to remove all macros

I have a game that I have have added multiple add modules to which has resulted in a large number of duplicate macros. Is there a simple way to delete multiple or all macros without deleting them one at a time
1705674430
The Aaron
Roll20 Production Team
API Scripter
The formatting is a little bit ugly, but here's a script that will let you do that.  Just run: !macro-cleanup And hit the  ❌  next to a player name to remove all their macros.  You can also remove individual macros with the  ❌  next to them. code: on('ready',() => { // ❌ const s = { button: `font-size: .6em; border: 1px solid #999;background-color: #ccc; border-radius: 1em; padding: .1em .3em;min-width:1.5em;text-align:center;`, tokenAction: `background: green; font-weight: bold; border: 1px solid #333; color: white;` }; const playerName = (()=>{ let players = findObjs({type:'player'}) .reduce((m,p)=>({...m, [p.id]: p.get('displayname')}),{}); return (pid) => players[pid] || '[Unknown]'; })(); const f = { li: (c) => `<li>${c}</li>`, ul: (c) => `<ul>${c}</ul>`, ol: (c) => `<ol>${c}</ol>`, b: (c) => `<b>${c}</b>`, subhead: (c) => `<h4>${c}</h4>`, ta: () => `<span style="${s.tokenAction}">TA</span>`, button: (label,command) => `<a style="${s.button}" href="${command}">${label}</a>`, mac: (m) => `${f.b(m.get('name'))} ${m.get('istokenaction') ? f.ta() : ''} ${f.button(`❌`,`!macro-cleanup ${m.id}`)}`, pla: (p,ms) => `${f.subhead(`${playerName(p)} ${f.button(`❌`,`!macro-cleanup ${ms.map(m=>m.id).join(' ')}`)}`)}${f.ul(ms.map(f.mac).map(f.li).join(''))}`, tree: (tree) => Object.keys(tree).map(pid=>f.pla(pid,tree[pid])).join('') }; on('chat:message', (msg) => { if('api' === msg.type && /^!macro-cleanup(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid) ){ let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname'); let args = msg.content.split(/\s+/).slice(1); if(args.length){ _.chain(args) .map((id)=>getObj('macro',id)) .reject(_.isUndefined) .tap((ms)=>sendChat('',`/w "${who}" ${ms.length} removed.`)) .each((m)=>m.remove()); } else { let macroTree = findObjs({type:'macro'}) .reduce((m,mac)=>({ ...m, [mac.get('playerid')]:[ ...(m[mac.get('playerid')]||[]), mac ] }),{}); sendChat('',`/w "${who}" ${f.tree(macroTree)}`); } } }); });
@The Aaron. Sorry for long delay but this was my first opportunity to try your script. Yes worked perfectly  thank you! Now I can have fun try to resurect my JS skills to work out why it worked :)