Minimize/Unminimize

Why doesn't this work???

It may be that only @peternlewis can explain why it's not unminimizing. If I had to guess, I'd say it's because a minimized window isn't the front window. (From the OS' perspective, it's barely a window.)

One workaround is to store the frontmost window's title before minimizing, then restore that specific window:

Download Macro(s): safari min-unmin test.kmmacros (3.6 KB)

Macro screenshot

Macro notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System information
  • macOS 14.7.1
  • Keyboard Maestro v11.0.3

Not ideal, probably, but it does work.

-rob.

1 Like

Once you minimize the window, there is a new front window (or perhaps no front window), the minimized window is implicitly moved to the back.

And even if it was the only window, it would not be the front window.

This sequence would likely work.

But I don't know for sure that the window is guaranteed to be the last window.

1 Like

A couple of good suggestions, so thanks.
I wrote an AppleScript, but it's kind of gross, because the window properties in different apps are different:

ell application "System Events"
	tell application "Music"
		--
		-- use miniaturized for Safari app, but use collapsed for Music app
		-- need to check the dictionary for each app
		--
		set windowslist to every window whose collapsed is true
		-- set windowslist to every window whose miniaturized is true
		repeat with thewindow in windowslist
			set collapsed of thewindow to false
			-- set miniaturized of thewindow to false
			
		end repeat
	end tell
end tell

versus

tell application "System Events"
	tell application "Calendar"
		--
		-- use miniaturized for Safari app, but use collapsed for Music app
		-- need to check the dictionary for each app
		--
		-- set windowslist to every window whose collapsed is true
		set windowslist to every window whose miniaturized is true
		repeat with thewindow in windowslist
			-- set collapsed of thewindow to false
			set miniaturized of thewindow to false
			
		end repeat
	end tell
end tell

I'm glad you got it working, but the solution you provided appears to be much different than the question you asked: You asked why a set of actions didn't work to minimize then unminimize a specific window, and that's what people answered.

But it seems, at least from reading your script, that your question was really "How do I unminimize any minimized window in any app?" What is the actual objective you're trying to accomplish?

If you're trying to unminimize all windows in all apps, you're much better off using window properties, which are the same across all apps. In particular, AXMinimized is true for any minimized window. Its use in unminimizing all minimized windows has been covered in this thread:

If you're asking something else, I'm unclear on what it is—I tried to answer the question you explicitly asked, which was about a single window in Safari.

-rob.

What I'm trying to do is part of a larger project, but I'll try to paint the context. Specifically, I'm trying to hide all apps so my screensaver runs on screens that have no menu bar, no icons, etc. But, what I have found is that certain Apple apps like Music and TV are treated differently than other apps by the Finder. The KM function "Hide all Apps" does not in fact do that (for all desktops and for all screens). When I say this, what I specifically mean is that if I hide all applications, and then switch to different desktop, certain applications become visible, like Music and TV, even though I did not un-hide them. I assume the Finder is doing this behind my back. The only reliable solution I have found is to minimize stubborn windows rather than hide the apps. This works and works well. But, to correctly deal with things when the screensaver ends, I have to un-minimize that which I've already minimized.

When I say certain things are "gross" what I mean is certain apps don't uniformly respect the same properties of the others, like "collapsed" and "miniaturized".

Hope this helps.

I'd like to try this approach. Is there a way to iterate over all applications that have visible windows?

Hey Ike (@ikenassi):wave:

If it’s minimizing all Application‘s Windows that you want to do then yes - but it may also work for the opposite purpose.

NOTE:: For this to work you’ll either need the Activate Application by Name String PlugIn or must code the part of that PlugIn for your self

  • Use the %Application%Foreground% Token to build a List of all Running Applications

  • in a Loop

    • use the PlugIn to activate the Application

    • minimize/unminimize Windows

to the others reading this topic - I was suggesting %ForegroundApplication% & %ForegroundApplication%All% instead of %Application%Foreground% which was a mistake… please be not confused by the next few replies including post 15.

Greetings from Germany :de:

Tobias

Wow! I didn't know this even existed. I'll try it! Thank you.

Cannot seem to install it. Running sequoia 15.1.1 and KM 11.0.3. Dragging the .zip to the KM icon in the toolbar does nothing.

Later: I dragged it to the menubar, not the dock. Now it's installed.

Where can I find %ForgroundApplication%?

It’s in the list of all Tokens…

If I am right you should use it as %Application%Foreground% to get every Application listed for your purpose.

I think you haven’t been able to find it because of a typo … fixed it above.

Greetings from Germany :de:

Tobias

I think maybe you mean %Application%Foreground%?

No. I tried both spellings. I cannot find the token. Did you mean this?
%Application%Foreground%

Dang !!

:man_facepalming::man_facepalming::man_facepalming:

@hemicyon thank you … of course you’re right … after revisiting the Application Token Page I now see my huge mistake …

Will fix it one more time …

I’m sorry guys …

Greetings from Germany :de:

Tobias

@hemicyon, @ikenassi

Corrected my mistakes above and added this comment for new readers:

Again, sorry for my fault and the confusion… sometimes I’m replying with a slower brain than my hands …

Greetings from Germany :de:

Tobias

What if the application is running in a desktop that is not the one currently active? This solution does not seem to work. It only works if the desktop is currently visible.

As soon as multiple desktops are involved, all bets are off because as far as I am aware, Apple has never released any public APIs for dealing with desktops.

Nope as far as I know, too—and it's one of the biggest issues for us in our apps. You'd think after however many years of Desktops/Spaces they'd be stable enough to let developers use the APIs, but apparently not.

-rob.

1 Like

Hello Ike (@ikenassi):wave:

Since there’s no Public API for Spaces/Desktops/Virtual Desktops as Peter (@peternlewis) & Rob (@griffman) already mentioned, you’ve only two options:

  • option 1 is using the full scale of windows of a particular Application per space (the Dock Menu of the Application has a setting for that) which in my opinion is the easiest or

  • option 2 where you have to use Jim‘s (@_jims) Macro for managing Windows of Applications using with Spaces (in Version 4) and maybe build your own handling routine where you’ve minimized your windows of which Application - where you can see that gets very complex.

Here is also a CLI tool that you maybe could integrate …

GitHub - davidpurnell/SpaceInfo: A command line app which returns MacOS spaces & display info

I’m using it I’m my Macros and it’s a cool nifty tool.

Greetings from Germany :de:

Tobias