Shortcuts output *on the command line*

I’m losing my mind on this. I created a Shortcut to query the power state of a HomeKit light and based on that either turn it off or on. I.e. it does a toggle (because apparently toggling power state is not something anyone ever wants to do!)

Anyway, the final step in the Shortcut is to get the power state again, as I want to be able to run the Shortcut in a script and the script to know what the resulting state is.

As you can see, it works fine to spit out “Yes” or “No” based on whether it’s now turned on or not. But, when I execute the Shortcut from the command line with shortcuts run "Toggle Canvas" I get nothing.

I have also tried the following variants based on this page and the shortcuts man page.

shortcuts run "Toggle Canvas" --output-type public.text
shortcuts run "Toggle Canvas" --output-path -
shortcuts run "Toggle Canvas" --output-path - --output-type public.text

None of them produce anything. The Shortcut toggles the light and I get no output. I also tried redirecting to a file and that file is just empty.

Does anyone know the secret incantation to get this to produce something?

Maybe a typo?
(And 20 more characters)

Run:

shortcuts run “Toggle Canvas” | cat

If you want the output in a text file:

shortcuts run “Toggle Canvas” > ~/path/filename.txt

Thank you!!!

I don’t quite understand why stdout has to be plumbed to stdin to see anything, but I will take a working solution.

Nothing to understand there, just a terrible implementation.

1 Like