1

I'm trying to create a shell script shortcut in the Shortcuts app that can hide folders in macOS (because tons of apps annoyingly create folders in the user Documents folder).

This is what I have: macOS Shortcut that I've made

It doesn't show it for some reason, but I selected "Shortcut Input" in the "Input:" dropdown.

When I try to run this on a test folder (via a Quick Action by right-clicking on it), I get an error notification that says The file "test folder" couldn't be saved in the folder "Documents".

Other attemps:

  • I tried setting the "Pass Input:" dropdown to "as arguments", which yielded this error when trying to run it on a folder:

enter image description here

  • I tried explicitly putting the shortcut input variable as an argument in the script (which yields the same errors): enter image description here

I'm running macOS Sonoma 14.5.

What is preventing this from working?

5
  • 1
    You aren't using any file argument with the shell script.
    – red_menace
    Commented Jul 4 at 18:32
  • "Tons"? I don't thin I've met even one. Commented Jul 4 at 18:44
  • @red_menace Updated my question to address that
    – gills
    Commented Jul 4 at 18:58
  • @MarcWilson Interesting, it must be relatively unique to the pro audio world. To name several on my machine: Adobe, Avid, Blue Cat Audio, Eventide, FabFilter, IK Multimedia, iZotope, oeksound, Universal Audio, among many others.
    – gills
    Commented Jul 4 at 18:59
  • 1
    @MarcWilson I have 15 (does that count as tons?), none are audio and none are used from Finder (only within an app).
    – Gilby
    Commented Jul 5 at 22:38

1 Answer 1

3

Shortcut Input is not something that will coerce to file items, which is what Run Shell Script wants for its input. Since the input is also a list, the usual way to handle them is to step through the items, for example:

for f in "$@"
do
    chflags hidden "$f"
done

Note that you can also set the Receive action to ask for folders if there is no input.

2
  • This worked beautifully, but I'd love to understand it more. If a Shortcut Input says it receives folders (or files), what type of item/data exactly is it receiving, if not file items?
    – gills
    Commented Jul 7 at 0:53
  • The input to an action can be file items, but it can also be images, rich text, dates, etc. Each action has settings that declare what it is expecting so that the workflow items can be set to the proper reference, and those items are passed to the action's input. In this case, instead of using regular shell variables for the input parameters to the shell script, the Shortcut Input variable is getting inserted into the script text field, which is failing because doing that just results in a name instead of the full path (you can see that by replacing the chflags command with echo).
    – red_menace
    Commented Jul 7 at 6:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .