Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 24, 2009, 07:37 PM   #1
MagicTramp
macrumors newbie
 
Join Date: Jan 2009
Applescrip help, Please. My head hurts.

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 -

Quote:
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 -

Quote:
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
MagicTramp is offline   0 Reply With Quote
Old Jun 24, 2009, 08:02 PM   #2
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
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
kainjow is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Head hurts... downyball iPhone 1 Aug 23, 2013 12:12 AM
Apple hurts the unaware lief iPod touch 5 Oct 28, 2012 09:30 PM
Here we go again. Will Apple finally go head to head against Google over the Nexus? depths Apple, Industry and Internet Discussion 87 Jul 14, 2012 12:22 AM

Forum Jump

All times are GMT -5. The time now is 05:21 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC