closing Finder window

Hi all !!!

Is there a way to close Finder windows without saving or considering dialog boxes or… no matter what ?

Thanks !

What do you mean?
Finder doesn’t ask for confirmation when you close a window.

Anyway the code below might help you in solving your problem:

# close all windows
tell application "Finder" to close every window

# close the top window
tell application "Finder" to close window 1

# close a specific window 
set TheNameOfTheWindowYouSeek to "Pegasus"
tell application "Finder"
	set allwindows to get every window
end tell
repeat with i in allwindows
	# getting some basic info on the window
	i's name
	i's id
	i's index
	if i's name is TheNameOfTheWindowYouSeek then
		tell application "Finder" to close i
	end if
end repeat

Thanks for the reply !

New to apple script. Mixed up Finder window and app window i guess. That app will not close. It presents a dialog that ask if i want to close all tabs preventing it to close.

What i want to do is close every window ( no matter what kind of window, regarless of saving it or dialogs or message or whatever) to start with a clean desktop. I know it can be risky, but i am ok with it.

Thanks again !

Pace

The following will generally do what you want but may not work with a few apps and unsaved work will be lost. Recalcitrant apps can be dealt with on a case-by-case basis.

set keepApps to {"Finder"} # add other apps that should not be quit

tell application "System Events"
	set activeApps to name of every process whose visible is true
end tell

repeat with anApp in activeApps
	try
		if anApp is not in keepApps then
			tell application anApp to quit saving no
		end if
	end try
end repeat

tell application "Finder"
	close every window
end tell

Source:
https://macscripter.net/viewtopic.php?id=32758