Using Quick Add to Archive Monthly Notes

What I’m trying to do

I’m trying to write a simple (not for me) script that I can run every month to archive the notes that were created that month.

I’ve boiled it down to the following steps:

  • Ask question “What month are you archiving?” - I will refer to this as “Response 1”
  • Rename folders called Current-Incidents and Current-Requests inside Tickets/“Response 1” to Incidents and to Requests
  • Create a folder inside Tickets/“Response 1” named Attachments
  • Move all files inside another folder also called Attachments but with path Attachments to the new Attachments folder except the files that are linked to by notes in the Tickets/In Progress folder
  • Ask question “What year will this be archived under?” - I will refer to this as “Response 2”
  • Move the Tickets/“Response 1” folder to Archive/“Response 2”
  • Ask question “What month are you starting?” - I will refer to this as “Response 3”
  • Create a new folder called “Response 3” inside the Tickets folder with sub-folders Current-Incidents and Current-Requests
  • Echo a reminder saying "Don’t forget to update the Metrics!!!

Things I have tried

To be honest I don’t really know. I have 0 or negative coding knowledge and after googling for a lot of hours on the last couple of days I started with a collage of stuff I found and started debugging and trying to fix all the errors shown in the console and I’m stuck with

async function main() {
    const month = await window.app.vault
      .inputPrompt('What month are you archiving?');
  
    // Rename folders
    await window.app.vault.rename(
      `Tickets/${month}/Current-Incidents`,
      `Tickets/${month}/Incidents`
    );
    await window.app.vault.rename(
      `Tickets/${month}/Current-Requests`,
      `Tickets/${month}/Requests`
    );
  
    // Create new Attachments folder
    await window.app.vault.createFolder(`Tickets/${month}/Attachments`);
  
    // Move all files from old Attachments folder to new Attachments folder
    const inProgressNotes = await window.app.vault.adapter.read(
      `Tickets/${month}/In Progress/.obsidian/attached_files.json`
    );
    const inProgressLinks = Object.keys(JSON.parse(inProgressNotes));
    const oldAttachmentsFiles = await window.app.vault.adapter.list(
      `Tickets/${month}/Attachments`
    );
    for (let i = 0; i < oldAttachmentsFiles.length; i++) {
      const file = oldAttachmentsFiles[i];
      if (!inProgressLinks.includes(`../Attachments/${file}`)) {
        await window.app.vault.rename(
          `Tickets/${month}/Attachments/${file}`,
          `Tickets/${month}/Attachments/${file}`
        );
      }
    }
  
    const year = await window.app.vault
      .inputPrompt('What year will this be archived under?');
  
    // Move folder to Archive
    await window.app.vault.rename(
      `Tickets/${month}`,
      `Archive/${year}/${month}`
    );
  
    const newMonth = await window.app.vault
      .inputPrompt('What month are you starting?');
  
    // Create new folder and sub-folders
    await window.app.vault.createFolder(`Tickets/${newMonth}/Current-Incidents`);
    await window.app.vault.createFolder(`Tickets/${newMonth}/Current-Requests`);
  
    console.log("Don't forget to update the Metrics!!!");
  }
  
  main();

which I’m pretty sure that is probably 99% wrong.

Any help is seriously appreciated.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.