No output from simple shortcut

I have very simple shortcut taking information about displays connected to the system and returning list. I try to get results from them into KM but receive nothing. The same shortcut called from Alfred’s workflow works correctly.

Is any limitation in “Execute shortcut” in KM?

Screenshot of shortcut below.

Show displays Macro (v11.0.4)

Show displays.kmmacros (1.6 KB)

I can't get it to fly either. But there are a couple of issues with your approach.

The shortcut saves the output as images so the macro can't display the result in a text window. You should save it to a file or the clipboard.

But even changing the shortcut's output to Names and routing the action to a file didn't return the names that the shortcut returned itself. I'm not familiar with the way in which the shortcut returned that information so maybe that's a clue.

As said above, the output of the Find Displays action in macOS Shortcuts is an image. But I think you can extract the text using a follow-up action, as shown here. It seems to work for me, but I don't have multiple displays, so you will have to test this yourself.

But in case of Alfred workload I don’t see images, just only names of displays. I assume that the data returned may be dynamically recognised as different types and receiving application make some declaration in which form it can process the data.

You could be 100% right. But my proposed solution may also work 100%. Did you try it? It seems to work for me.

No it doesn’t work. But your Shortcut is different - it filters only one display - my receives info about all.

Then change my macro. Remove my filter for "Main Display." Then test it. It may work. I'm sorry I added a filter, which seems to have messed you up.

No, in my case using Name in Shortcut doesn’t change anything - no output.
I use macOS Tahoe 26.0.1

That's odd, since my macro works for me 100% fine. So why doesn't it work for you? I don't know. I can't find a second display to test my macro with multiple displays. Maybe someone else here has 2 displays and can test my macro. It would be nice to get a second opinion.

Here's what I was using to get all the Display names:

I was able to get a list of Display names using "Show Name" and making sure the popup for Name was "Text":

Apparently Shortcuts is returning windows not text. Here's what the revised shortcut returns on my system (correctly):

And that's what popus up when you run the "Execute Shortcut" macro. But Keyboard Maestro's "Display results in a window" still doesn't pop up. It may be that Shortcuts is displaying the text in a window and returning the window. And Keyboard Maestro doesn't know what to do with that.

Did you see the phrase "Page 1 of 2" in your output. Can you show me page 2? I think you will find both of your displays.

Yes, I noticed that immediately on the first run of his scheme. But I think the OP wants the names of the displays not windows for each display nor a window with the display names in it.

Have you tried adding the "Split Displays by New Lines" action in Shortcuts directly after the "Find Displays" action. For me, that seems to fix the problem that occurs for other "Find" actions that are similar to "Find Displays". But I was unable to test "Find Displays" because I have only one display.

Try this Shortcut:

...where "Displays" in the second action is set to

When used in this macro:

...the result is:

(I do find Shortcuts's handling of data, especially input and output, to be "unintuitive" at best...)

2 Likes

In fact, just editing my existing Shortcut to match yours required more mousing around and wild clicking than I've ever had to done in my adult life. AppleScript, Automator, Shortcuts ... one day, perhaps, Apple will discover Keyboard Maestro's approach to automation.

BTW, I was looking for (as an alternative to Shortcuts) a simple command line option to return just the names of the displays. If I'd found one, I would have suggested that approach.

It's a problem of getting usable names. I'd get the data by parsing the result of

system_profiler SPDisplaysDataType

...but the names there don't always match the names used in the OS, particularly for any built-in display. Mind you, Shortcuts gets it wrong too -- "Built-in Display" vs the "Window" menu's "Built-in Retina Display"...

Which is exactly what this macro does—I just ripped it out of a larger macro that gathers all sorts of system info. Lots of parsing to get usable text out :).

Display Info.kmmacros (16 KB)

After a few seconds, you get...

-rob.

1 Like

The form of shortcut from @Nige_S works for me, even without getting the name, I suppose that direct (internal in Shortcuts) conversion from”Display object” to “Text Object” helps KM to get the results. Good, but it creates following questions in my head:

  • Why calling the same shortcut from Alfred workflow give the result without such conversion
  • What API or methods can be used by program like KM or Alfred to call Sortcuts and receive the results (I’ve see in description of JavaScript API in Drafts, that it probably use x-callback-url). Maybe @peternlewis uncover a bit of internals of KM in this case?
  • Treatment of objects/vars in Shortcuts was always mysterious for me - I’m surprised how Apple can propagate mechanism like Shortcuts without good description of product. Creating in shortcuts is always the big pain and hours of understanding what the author had in their mind creating this. But the isolation (aka sandboxing) of applications sometimes doesn’t give other possibilities - for example I have not found how to call ssh with getting the key from ssh agent without calling terminal directly. Alternative is using Shortcut “Run Script over ssh”, but it includes their own generated key (and exporrting only public part). There is no possibility to import existing key.

BTW

I started exploration of names of available external displays because of .., Moom, which seems to be nice tool (I still testing it and try to understand - this is not easy for me in some aspects). Unfortunately it doesn’t have option to setup selected Layout only for specified display type/name, so the idea to get display names, put KM to work and use AppleScript to setup selected Layout. But maybe I haven’t learnt and understood Moom too much. (@griffman seems to be Master of Moom here).

Wow I didnt know about command system_profiler :grinning_face: :ok_hand:

I know that this forum is dedicated to KM, but cannot resist to propose solution based on my lovely awk for this section (filtering results from system_profiler:

system_profiler SPDisplaysDataType  | awk '/^        [^ ]/ { sub(/:/, "",$0); printf($0); } /^ +Resolution:/ { printf " [%s x %s]\n", $2 ,$4; }

what gives in my system:

Color LCD [2560 x 1600]
DELL U3419W [3440 x 1440]

1 Like