Jump to content

The stable way to close all windows


Recommended Posts

I have been trying to make a workflow, and in one step it needs to close all windows. Currently, I have tried the following applescript:

on alfred_script(q)
tell application "Finder"
	set visible of every process to false
end tell
end alfred_script

and also 

on alfred_script(q)
tell application "Finder"
	set visible of every process to false
	if q contains "all" then
		tell application "Finder"
			close every window
		end tell
	end if
end tell
end alfred_script

which are all found online. I don't know applescript particularly well, and both of them seem fine. But there's one trick thing keeps happening: sometimes some windows will not be hidden. And using a simple ShortCut seems to fix this issue:

image.thumb.png.d38c38366f7157513ca9a37927a2764a.png

But I would like to avoid this since it hurts the distributivity. The complete workflow can be found here (with old script currently) if this helps debugging. 

Demo:

ezgif.com-gif-maker.thumb.gif.34cbd3d4a72c5951cc65037112f9a505.gif

this is with workflow:

image.thumb.png.578f6e61dcd9fab040c729bda2e885e2.png

and the launch apps list only contains VSCode, so basically some apps like Telegram is not hidden. I'm open to any solutions which can close windows more stably. And I know two scripts I have tried are all using Finder's hide other functionality, which make finder shows up. If it's possible I would like to make Finer be hidden as well.

 

Edit: To be clear, I know there exists apps like bunch: But what I'm trying to do is to just hide those apps, not completely quit them, since I have huge amount of pdf files in Preview and also default apps. So to quit and reopen them will be a waste of time. 

Edited by pbb
Link to comment

It's not clear if you want to quit all apps or hide them? If you want to hide them, here is a script that hides all apps. 

 

on alfred_script(q)
    tell application "Finder" to activate
    tell application "System Events" to keystroke "h" using {command down, option down}
    tell application "Finder" to activate
    tell application "System Events" to keystroke "m" using {command down, option down}
end alfred_script

 

 

If you want to quit them, Automation Tasks (❤️), the Alfred 5 comes with this out of the box 😁. See screenshot and this

 

image.jpeg.1109f02dfe603e6ed20cef26f84dbe3d.jpeg

 

Edited by andy4222
Link to comment
1 hour ago, andy4222 said:

It's not clear if you want to quit all apps or hide them? If you want to hide them, here is a script that hides all apps. 

 

on alfred_script(q)
    tell application "Finder" to activate
    tell application "System Events" to keystroke "h" using {command down, option down}
    tell application "Finder" to activate
    tell application "System Events" to keystroke "m" using {command down, option down}
end alfred_script

I want to hide them. I think the first two lines in the alfred script box works well, but the last two lines make me quite nervous... So basically macOS treat Finder completely differently even for its hiding mechanism?

Link to comment

Why do those 2 script lines make you nervous :)? I mean you could read the Apple docs if you want to deep dive, but it pretty much is self descriptive. To my knowledge, macOS default's to Finder app is everything is minimized. If you hide everything manually, you'd see that Finder becomes the active app (doesn't necessarily mean it is the front most app)

Edited by andy4222
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...