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.
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.
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.
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.
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.
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 :).
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).
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: