How Can I Create a Series of Minimal App Windows That Only Consist of a Titlebar?

Yes.

I'm not sure how you want to list them, but presumably.

I would like to present them in a Prompt With List menu and then, when any particular item is chosen, activate the corresponding window, which would switch to the Desktop Workspace containing that window.

I'd also like to be able to query which window was visible on the current desktop.

Well, presuming there are a fixed number of them, each could have a specific ID associated with them, which you could use in your Prompt With List macro to activate them.

Whether that activates the Desktop, I don't know, that’s an Apple spaces issue.

As for which is visible in the current desktop, I'm not sure about that either. There are no Spaces public APIs, so generally you can't do such things directly, you can only do them indirectly. Probably it is possible.

That is exactly what I'm trying to do here, have an identifying window on each Desktop Workspace so that when that window is activated, the display changes to the appropriate Space that contains the identifying window.

This Forum Q&A seems to address the issue:

In the situation we're considering here, you're suggesting a set of Custom HTML Prompt windows, so I presume those would all be KBM-owned windows, right?

When I use KBM to run an AppleScript and display the results in a window, it gets the title "Keyboard Maestro - AppleScript Results".

image

But when I leave that window open and run a script like the one from Chris Stone in:

https://forum.keyboardmaestro.com/t/how-to-list-all-open-windows-on-a-desktop/23969/2

then those KBM-results windows are not listed as being windows active in the current desktop, even though they are "always on top" as well.

I've never used Custom HTML Prompt unless it was part of someone else's shared macro package. I'll experiment, eventually, to see if it might work for what I'm trying to do here. Meanwhile, if anyone else knows that Custom HTML Prompt windows are indeed listable by System Events in an AppleScript, that would help move my question forward.

Thanks.

That's because Chris's script lists windows belonging to application processes whose background only is false -- the KM "Display" windows belong to the Keyboard Maestro Engine, whose background only is true.

A quick test shows that Custom HTML Prompts also belong to KM Engine, and can be listed with eg:

tell application "System Events"
	tell application process "Keyboard Maestro Engine"
		return every window
	end tell
end tell
1 Like

@Nige_S is correct.

I have amended the post @August cites above to make this clear.

How to List All Open Windows on a Desktop - #2 by ccstone

1 Like

Thanks @Nige_S and @ccstone,

That's very helpful. With your help I'm learning a lot of AppleScript subtleties that the tutorials that I've seen don't touch.

A quick test of @Nige_S's script above shows that an AppleScript results window is displayed with the title bar saying, "Keyboard Maestro - AppleScript Results" while the script to list KBM windows produces the line:

window Keyboard Maestro - AppleScript Results of application process Keyboard Maestro Engine

Keep in mind that @Nige_S' script in post #11 returns window objects to AppleScript.

It is not intended to create a proper report but is a demonstration of how to get the window objects from which a report would be generated.

That explains the mismatch between the window title and what is displayed by the script. Printing the script results prints what is printable of the window data. The Title needs to be explicitly extracted from that data to be printed properly.

Thanks.

It's AppleScript, (in)famous for being "write what you'd say" -- if you can get a list of window objects with every window and each window object has a name property, IRL you'd say "tell me the name of every window". Sure enough:

tell application "System Events"
	tell application process "Keyboard Maestro Engine"
		return name of every window
	end tell
end tell

(OK, so that doesn't work all the time! But it does work often enough that it's worth a try before digging into the documentation.)

Again, that'll get you a list object. You'll need to process further in AS to get text that KM can easily use. I daren't suggest how because I've lost track of what you're aiming for!

Well, you opened the can of worms with that comment.

The overall point is to create minimalist windows that have titles that can be listed.

I'm exploring this subthread because Peter suggested that the Custom HTML Prompt action could be used, but I had initial trouble listing those windows because, being owned by the KBM Engine, they were overlooked because the Engine was "background only". Your help in this subthread seems to have handled that.

To complete that idea, I still need to try creating Custom HTML Prompt windows, giving them custom titles, and listing them as you just described, to fully test this option.

The larger context of why I want the minimalist windows is to use them as Desktop Workspace Identifiers (DTWSID) to put one on every Desktop Workspace so there is a text name that stays with the Desktop even if I rearrange their order in Mission Control, or even if Mission Control gets set to rearrange them automatically. I have multiple threads I am exploring to see how I might be able to make useful DTWSIDs.

Listing all those app windows' titles gives me a list of Desktop Workspace names so that, simply by activating that named window, I switch to that desired Desktop as the active Desktop Workspace.

This minimalist window approach is one route I am exploring. I am also looking at having a floating Notes window on each Desktop, a TextEdit window, and a couple of other free apps that have been around for years, Text Do and Folding Text, or maybe a flexible combination of all of them at once.

The key is that Text Do and Folding Text also behave like Notes and TextEdit when rebooting (if I don't close the app first), they reopen all their previous windows in their original desktops. (I had previously tried Stickies, but Stickies reopen all in the first desktop and having to move 20 Stickies to their respective Desktops repeatedly, quickly became annoying.) I don't know yet if KBM's Custom HTML Prompt can be made to work like this.

All this is because I have become addicted to named Desktops and I see repeatedly in various Stack Exchange and Apple forums that many people are as chronically dissatisfied as I am with Apple's lack of support for Desktops. I would love to be able to recommend my solution. But I can't.

I have been able to name my desktops by using CurrentKey, which I have learned uses this same approach as I have outlined above, he hides a thin app window behind the Menu Bar with a window title that is the name of the desktop and then activates that window to change desktops. But CurrentKey has been withdrawn for various reasons. So I can't offer it as a solution.

I've been exploring the question of whether I could imitate the named desktop switching of CurrentKey by using KBM and AppleScript, etc. So far, the answer is that it is not impossible.

That's a handy cut-out-and-keep reminder of what you're trying to do, but I was actually being more specific -- what's your aim with the AppleScript? That will determine what (if anything) you need to return to KM, which will determine how you process the list object.

Two obvious examples -- you want to know if a particular window is present, or you want a list of windows to iterate through.

For the first:

set inst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
    set winName to getvariable "Local_winName" instance inst
end tell

tell application "System Events"
    tell application process "Keyboard Maestro Engine"
        if name of every window contains winName then
            return 1
        else
            return 0
        end if
    end tell
end tell

And for the second:

tell application "System Events"
    tell application process "Keyboard Maestro Engine"
        set AppleScript's text item delimiters to return
        return (name of every window) as text
    end tell
end tell

Thanks for being an interested listener. It gets clearer and simpler every time I tell it.

This would be equivalent to:

if the window named winName exists then
        return 1
else
        return 0
end if

which would negate the need to enumerate names of all windows. A more compact version would be:

return (exists the window named winName) as integer
3 Likes

Nice!  :sunglasses:

1 Like

I want a list of windows to use in a Prompt With List menu to pick which window to activate.

BTT can do the following

  • list of all open windows of all apps of the active desktop (and go there)
  • list of all open windows of the front app of the active desktop (and go there)