Reset Reminders Completed

I have several Reminders lists that are checklists that are performed on a regular basis. I check the items then I end up selecting each item and unchecking the item to start the checklist again. I am trying to automate this, but I’m not a programmer. From other examples, here is what I tried using Scriptable and Shortcuts. In shortcuts, I am trying to select a particular List of reminders like “Leave RV Site” which has about 40 items that I do every time we leave an RV site. I would like to select this list and reset all completed items to start the list again.

In Scriptable:

var reminder = Pasteboard.pasteString();

let all = await Reminder.allCompleted();

for (let r of all) {
console.log (reminder);
if (r.title == reminder){
r.isCompleted = false;
r.save();
}
}

return reminder;
Script.complete();

In Shortcuts:

https://www.icloud.com/shortcuts/0b8dd28459074499b09190ada6bab376

The completed items title shows properly in Shortcuts, but the clipboard contents in the scriptable side seems to be Null. When I hard code a string, it seems to work fine. I’m happy to try a completely different approach if necessary.

I was able to achieve my desired result, but not using the clipboard argument. Here is my revised scriptable code. Apologies that there is probably a more efficient approach.

Instead of looping in the shortcut, I passed the Title from Reminders as an array and iterated through in the scriptable program.

var reminder = args.shortcutParameter;

let all = await Reminder.allCompleted();

for (let r of all) {
for (i in reminder) {
if (r.title == reminder[i]){
r.isCompleted = false;
r.save();
}
}
}
Script.complete();

Nice! So that’s working? It looks like you might be looping through each character in the passed in reminder title.

Here is code that should do the same thing, if you’re curious:

const reminderTitle = args.shortcutParameter;
const allCompleted = await Reminder.allCompleted();
const completedReminderWithSameTitle = allCompleted.find(
  completedReminder => completedReminder.title === reminderTitle
);
if (completedReminderWithSameTitle) {
  completedReminderWithSameTitle.isCompleted = false;
  completedReminderWithSameTitle.save();
}
Script.complete();