Minimize/Unminimize

I have a solution which I’ll post shortly. It’s not ideal. It requires one to know which property to use for each application: minimized or collapsed, which you can find out by looking at the AppleScript dictionary. This varies by application.

But it works with multiple desktops.

Summary of the general problem is this:
When applications are hidden, I want them to stay hidden. However, some of Apple's apps do not stay hidden when you switch to the desktop in which they're running. I worked on this for a long time. I call these apps "stubborn". Ultimately, I solved that problem by minimizing certain apps instead of hiding them. But, if they're minimized, I need to un-minimize them eventually. However, that didn't work if those apps reside on different screens. But I solved that problem as well.
Here's one solution. It's not pretty. For each application that's "stubborn", you have to know (by looking at the AppleScript dictionary for the app) what the "minimization" property is. It might be "minimized", or it might be "collapsed" and for that app you have to choose the relevant property. The code has comments to do this. I don't know why there are two properties for essentially the same thing. I also don't like that I had to create separate actions for each app, but I couldn't find a reliable way to put the apps in a list and invoke the action repeatedly for each app in the list.

Any suggestions are welcomed.

Stubborn apps hide and show.kmmacros (24.5 KB)

Does the AXMinimized window property not work for all windows? It should, unless there's something weird about being on another desktop.

-rob.

It might. I’ll try it.

No, it doesn't work consistently. The solution I uploaded for minimize/unminize works across all desktops and all screens. I'll stick with that.

This solution works across all spaces and screens...

set theIDs to {"com.apple.MobileSMS", "com.apple.Music", "com.apple.TV"}
repeat with anID in theIDs
	if application id anID is running then
		activate application id anID
		tell application "System Events"
			set anApp to (application process 1 whose bundle identifier = anID)
			tell anApp
				set windowslist to every window
				repeat with thewindow in windowslist
					-- setting to true means it's minimized, false it's maximized
					set value of attribute "AXMinimized" of thewindow to false
				end repeat
			end tell
		end tell -- system events
	end if --running
end repeat

So it does work consistently? I thought it should, given it's a macOS attribute. Glad you got it sorted and simplified!

-rob.

I had to apply the minimization to all windows of the app.

Weird, so it doesn't work if you try to check the value before switching it?

if value of attribute "AXMinimized" of thewindow is true then
	set value of attribute "AXMinimized" of thewindow to false
end if

Perhaps that data isn't available to AppleScript for windows on other spaces? If so, then it's weird that it lets you set the value, even though you can't read the value.

-rob.

I’m experiencing some timing issues. Having to throw in some delays on activation and minimization.

Will try your test and see what happens.

I’m still not getting this to work reliably. I’ll have to come back to it tomorrow or so.