Shortcut (macOS) works, but not from Quick Actions

This one’s got me stymied.

I’ve created a shortcut for macOS that makes multiple copies of a folder.

What it should do:

  • Take a folder.
  • Choose a text file with a list of names for the copies.
  • Choose a folder to hold the copies.
  • For each name in the list from the text file, make a copy of the folder in the “container” folder, and rename it with the name from the list.

So if I want to copy a folder called Test, I want to store my copies in a folder called Copied, and my list has the names Gryffindor, Hufflepuff, Ravenclaw, and Slytherin, I should end up with folders with each of those names inside Copied.

Here’s what’s baffling. The shortcut on the left (Duplicate Folder backup) in the image below works exactly as expected. The shortcut on the right (Duplicate Folder) makes the first copy, then tells me there was a problem running the shortcut. And of course it doesn’t tell me what the problem is.

In this instance in Duplicate Folder, I’ve got a folder created from the shortcut input, which is called “Folder to copy” in the loop. But I’ve also tried omitting that step, and just acting directly on the shortcut input in the loop. Both approaches show the same behavior.

Is there something obvious that I’m missing? Edited to add: The shortcuts are identical except for how they get the folder to be copied.

A quick suggestion, if you share a link to the shortcut, it means people can test and experiment with *exactly* what you have without having the additional effort to recreate it from a screenshot with the risk of inadvertently getting something wrong.

Okay, I’ve put together a few things for you to take a look at.

First of all I created a text file to use as follows:

Gryffindor
Hufflepuff
Ravenclaw
Slytherin

I then set up a copy from folder with some text files in that folder and some sub-folders (just one folder depth), and a copy to folder.

I reproduced an approximation of your quick action enabled shortcut and included some alerts so you can track what is going on.

Regardless of what folder structure is passed in, it always fails at the point of carrying out the save operation on the second loop iteration. It seems unlikely to be a memory issue, but only the Shortcuts devs could tell you for sure I think. Short story on this one is I don’t think Shortcuts’ file management is up to the job.

It’s also interesting to see it work int he first place as folders and files are different objects in Shortcuts and the file operation actions are specifically geared to files - they never seem to mention working with folder objects unless they are themselves geared around folders. There is certainly an overlap, but it may even be down to it not being an officially supported feature doing such things with folders. :person_shrugging:t2:

But, I can offer an alternative approach that does seem to work in my testing. Since you are on the Mac you have access to all the built in automation tools, including shell scripting, and the shell is a a perfect tool for any file and folder management automation.

As a result I substituted in a call to a shell command within the loop - to replace the failing Shortcuts copy.

FWIW, you might be able to make it fractionally more efficient by rewriting it to run a single script action rather that four in a loop (build the commands in a loop then excute them as one script), but it should be pretty darn quick as it is and I figured this was algorithmically closer to do four separate executions.

While this does not really provide an answer to the underlying question of “why?”, I think it should give you a practical, and potentially more efficient, workaround.

1 Like

Thanks for this reminder! I’m new to shortcuts, so I’d forgotten that sharing was possible.

I’ve altered the working shortcut slightly so it takes input from the share sheet. I’ve confirmed that it works on iOS/iPadOS as well as Mac, so I’m linking it here in case anyone finds it useful: Duplicate Folder — iOS and macOS.

1 Like

Many, many thanks for this! It works beautifully. (And honestly, I’m a little relieved that I’m not the only one who can’t answer the “Why?” question.)

I really appreciate your help. :smile: