Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MagicTramp

macrumors newbie
Original poster
Jan 14, 2009
19
0
I'm trying to tell the Finder to do the following please read and/or reenact the following with 2 finder windows open.

Switch from window 1 to 2
close window 1.

^ Thats based on there being < 1 windows. Code -

tell application "Finder"
activate
tell application "Finder" to set FinderWindowOpen to ((count each Finder window) > 1)

if (FinderWindowOpen) then
tell application "System Events" to tell process "Finder"
keystroke "`" using {command down}
keystroke "w" using {command down}
end tell

However, if there is MORE than 2 windows open i want finder to close ALL open windows, then open ONE new fresh one.

If the above code looks like its missing stuff, heres the full code.
The problem i am having is the first bit works, but getting Finder to see if theres more than 2 windows open then closing them all does not.

Full code -

tell application "Finder"
activate
tell application "Finder" to set FinderWindowOpen to ((count each Finder window) > 1)
set FinderWindowMore to ((count each Finder window) < 100)

if (FinderWindowOpen) then
tell application "System Events" to tell process "Finder"
keystroke "`" using {command down}
keystroke "w" using {command down}
end tell

else if (FinderWindowMore) then
tell application "Finder"
activate
end tell
tell application "System Events" to tell process "Finder"
keystroke "w" using {command down, option down}
keystroke "n" using {command down}
end tell

end if
end tell
 
This should work:
Code:
tell application "Finder"
	activate
	
	set numWindowsOpen to count each window
	
	if (numWindowsOpen is equal to 2) then
		close window 1
	else if (numWindowsOpen is greater than 2) then
		close every window
		make new Finder window
	end if
end tell
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.