Skip to content

Copying Multiple Attachment Paths at Once #435

Closed Answered by bthomaslee
bthomaslee asked this question in Q&A
Discussion options

You must be logged in to vote

I used ChatGPT to generate the following code, which allows me to copy-to-clipboard all attachment paths, from multiple selected items, all at once (with each attachment path on a new line):

if (!items?.length) return;

async function getAttachmentPath(item) {
  if (item.isAttachment() && !item.isNote()) {
    return await item.getFilePathAsync();
  } else if (item.isRegularItem() && !item.isAttachment()) {
    let attachment = await item.getBestAttachment();
    return attachment ? await attachment.getFilePathAsync() : null;
  }
  return null;
}

(async () => {
  try {
    // Retrieve all file paths asynchronously
    const filePaths = await Promise.all(items.map(getAttachmentPath));
   …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by bthomaslee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant