Show view options

Finder → open folder → show view options (commad + j)-> All Window
How scripting?

I use GUI Scripting (enable access for assistive devices) - no result:

tell application “Finder”
activate
tell application “System Events”
tell process “Finder”
tell window id 9 – id is various
tell group 1
click radio button “All windows”
end tell
end tell
end tell
end tell
end tell

I calculate “id window of show view options”: Get windows (active finder) vs (inactive finder)

Hi.

I didn’t get it to work. I noticed that the window opened by “command j” has the same name as the window of the opened folder. Maybe that is the problem.

I got “System Events got an error: Can’t make radio button “All windows” of group 1 of frontmost of process “Finder” into type UI element.” when I tried the following:

tell application "Finder" to activate
tell application "System Events"
	(keystroke "j" using command down)
	delay 1
	tell process "Finder"
		tell frontmost
			tell group 1
				tell radio button "All Windows"
					click
				end tell
			end tell
		end tell
	end tell
end tell

What are you trying to do? There is a “Set View Options” script that you could edit here - http://www.apple.com/applescript/toolbar/

My example not working, as well as yours. I do not know why. A problem not in identity of names of windows. I calculated and substituted identification number of a window manually. Number can be calculated having looked list ID of windows active Finder and inactive. Required ID will be difference of these lists.

What are you trying to do? There is a “Set View Options” script that you could edit here - http://www.apple.com/applescript/toolbar/

http://images.apple.com/applescript/toolbar/scripts/setviewopt.sit
In these examples there is no switching property “All windows”

Problem, most likely that the window consists of two parts (is divided by feature, as well as a window command+I). ObjectInspector shows two unknown elements on a way to All Windows

The script gives out a mistake. (NSReciverEvalutionScriptError: 4) What method had been counted group?

Actually, Jacques’ example works (as usual.)

I replaced part of my script with his, opened a folder making it the front window, and ran the script.


tell application "Finder" to activate
tell application "System Events"
      keystroke "j" using command down
      delay 1
		tell application "System Events" to tell front window of process "Finder"
		click radio button "All windows" of radio group 3
	end tell
end tell

If the folder’s window wasn’t frontmost before running the script, the script errored.

Do you mean the “View options” window? Did you count groups from the bottom up? That would mean what I thought was group 1 was group 3.

EDIT: I put the delay back in - the script seems to need it, at least sometimes.

Hi.

On my machine, the index numbers of the radio groups in the View Options window vary from run to run. The only way to pin down the group containing the “All windows” button is to go hunting for it with a repeat loop.

This works for me. If it’s run as it is, then ” assuming you choose a folder whose window’s current view is either list view or icon view ” it’ll open the View Options window for that view, click the “All windows” button, and close both the window and the View Options. With the (* commented *) lines uncommented, it’ll do both list and icon view options and restore the folder window’s original view.

tell application "Finder"
	open (choose folder)
	(* set originalView to current view of Finder window 1
	set current view of Finder window 1 to icon view *)
	my allWindows()
	(* set current view of Finder window 1 to list view
	my allWindows()
	set current view of Finder window 1 to originalView *)
	close Finder window 1
end tell

on allWindows()
	tell application "System Events"
		tell application process "Finder"
			set frontmost to true
			if not ((first window whose description is "floating window") exists) then keystroke "j" using command down
			repeat with rg in radio groups of window 1
				if (radio button "All windows" of rg exists) then
					click radio button "All windows" of rg
					keystroke "j" using command down
					exit repeat
				end if
			end repeat
		end tell
	end tell
end allWindows

Thanks, Nigel.

Next time a GUI script errors when it looks like it should work, I’ll try a repeat loop.

j

This site is never carried out: (

Here such example too does not work:

tell application “System Events”
tell application process “Finder”
tell application “Finder” to open desktop
repeat
set frontmost to false
set a to id of windows of application “Finder”
set frontmost to true
set b to id of windows of application “Finder”
if a is b then
keystroke “j” using command down
else
exit repeat
end if
end repeat
repeat with itm in (a & b)
if (itm is not in a) or (itm is not in b) then exit repeat
end repeat

	get window id (contents of itm) of application "Finder"
	
end tell

end tell

Sorry. Here a correct example. But Here nothing is switched.

tell application “System Events”
tell application process “Finder”
tell application “Finder”
activate
open desktop
end tell
tell menu bar 1
tell menu “View”
if exists menu item “Show view options” then
click menu item “Show view options”
end if
end tell
end tell

	repeat
		tell application "Finder"
			set frontmost to false
			set a to id of windows
			set frontmost to true
			set b to id of windows
		end tell
		if (count of a) is not (count of b) then exit repeat
	end repeat
	repeat with itm in (a & b)
		if (itm is not in a) or (itm is not in b) then exit repeat
	end repeat
	
	
	repeat with rg in radio groups of window id (contents of itm) of application "Finder"
		if (radio button "All windows" of rg exists) then
			click radio button "All windows" of rg
			exit repeat
		end if
	end repeat
	
end tell

end tell

Hi, KIA.

That’s because window id (contents of itm) of application “Finder” is something that belongs to the Finder when you script the Finder directly. With GUI scripting, you’re scripting a process in System Events, so you have to use an appropriate reference for a window in that proces.

Because the View Options window is a floating window, it should turn out to be the frontmost window (or window 1) in the process. To click in it, the process itself must be the frontmost one in System Events too. That’s why the first thing my script does with the process is to set its frontmost to true.

If my script doesn’t work for you, it may be that you need to insert a very short delay or two to allow the View Options window time to open and/or for the process to become frontmost.

Hi KIA.

I was only able to get your window id script to work on the desktop folder, but I changed the beginning of Nigel’s script to do what I think you are trying to do - cycle through open windows, including the desktop folder.

tell application "Finder"
	activate
	open desktop
	repeat while window 1 exists
		my allWindows()
		close Finder window 1
	end repeat
end tell

on allWindows()
	tell application "System Events"
		tell application process "Finder"
			set frontmost to true
			if not ((first window whose description is "floating window") exists) then keystroke "j" using command down
			repeat with rg in radio groups of window 1
				if (radio button "All windows" of rg exists) then
					click radio button "All windows" of rg
					keystroke "j" using command down
					exit repeat
				end if
			end repeat
		end tell
	end tell
end allWindows

Hi, can I just point out that the inspector (the stay-open get info panel) is also a floating window? You’ll have to check the title of the menu item.

After closing a window of the folder, the first window will be floating. This code does not work.

tell application “Finder”
open desktop
(* set originalView to current view of Finder window 1

set current view of Finder window 1 to icon view )
my allWindows()
(
set current view of Finder window 1 to list view

my allWindows()

set current view of Finder window 1 to originalView *)
close Finder window 1
end tell

on allWindows()
tell application “System Events”
tell application process “Finder”
set frontmost to true
if not ((first window whose description is “floating window”) exists) then keystroke “j” using command down
delay 4
repeat with rg in radio groups of window 1
if (radio button “All windows” of rg exists) then
click radio button “All windows” of rg
keystroke “j” using command down
display dialog “Ok”
exit repeat
end if
end repeat
end tell
end tell
end allWindows

No Ok! :frowning:

I already spoke, that the inspector shows two unknown objects.

<AXApplication: “Finder”>
<AXWindow: “UI Element Inspector”>



<AXRadioButton: “All windows”>

Attributes:
AXRole: “AXRadioButton”
AXRoleDescription: “radio button”
AXChildren: “<array of size 0>”
AXParent: “”
AXTitle: “All windows”
AXWindow: “<AXWindow: “UI Element Inspector”>”
AXPosition: “x=610 y=76”
AXSize: “w=136 h=18”
AXEnabled: “1”
AXValue: “1”
AXMinValue: “0”
AXMaxValue: “2”

Actions:
AXPress - press

KIA, sorry this is a little off-topic but I just wanted to say that you should probably get into the habit of putting all your code that your trying to show people inside the coding tags. All you have to do is hit the Applescript button and paste your code in between. This makes it easier for people to open your script and it distinguishes it a little better from your normal text. Good luck anyway!

Hi KIA.

Did you try the script I posted? I tested it before posting and just tested it again. It does work.

This is incorrect. The floating window (first window whose description is “floating window”) contains information about the next finder window (window 1) that opens. Once you open that (view options) window, it stays open (unless you click its red “close” button) as long as a Finder window is open.

So the script opens the “View Options” window, clicks “All windows” closes window 1 - window 2 becomes window 1. “View options” is still open (if it isn’t, the script reopens it) and the process repeats until all windows are closed.

I also get a different result from UI Element Inspector when focused on the view options window - no unknown objects:

<AXApplication: “Finder”>
<AXWindow: “Applications”>

<AXRadioButton: “All windows”>

Attributes:
AXRole: “AXRadioButton”
AXRoleDescription: “radio button”
AXParent: “”
AXTitle: “All windows”
AXWindow: “<AXWindow: “Applications”>”
AXTopLevelUIElement: “<AXWindow: “Applications”>”
AXPosition: “x=1038 y=127”
AXSize: “w=136 h=18”
AXEnabled: “1”
AXValue: “0”
AXMinValue: “0”
AXMaxValue: “2”
AXFocused (W): “0”

Actions:
AXPress - press

Try running the script. Post the results. We’ll sort this out.

j

EDITED: in an attempt to be more clear.

Hi again KIA.

Not to beat a dead horse (yet here I go :rolleyes:) but I noticed one thing. I said:

but I missed the line of the script that closes it. It is reopened for the next Finder window, but if all windows have closed, the “View Options” window will close, too (good thinking Nigel.)

So this is the script explained:

tell application "Finder"
	activate --brings Finder to the front
	open desktop --opens the Desktop in Finder window 1
	
	repeat while window 1 exists --the script cycles through open Finder windows
		my allWindows() --the handler processes window 1
		close Finder window 1 --window 1 closes (if window 2 exists, it becomes window 1 in this repeat loop)
	end repeat --the scripts stops after all Finder windows have been closed
end tell

on allWindows() --processes Finder windows
	tell application "System Events"
		tell application process "Finder"
			set frontmost to true --this line puts the next Finder window 1 in front, the next line reopens "View Options" (with information for the new window 1) and it becomes the frontmost window so its "All windows" button can be clicked
			if not ((first window whose description is "floating window") exists) then keystroke "j" using command down
			repeat with rg in radio groups of window 1 --finds and clicks "All windows"
				if (radio button "All windows" of rg exists) then
					click radio button "All windows" of rg
					keystroke "j" using command down --closes "View options" so it is closed after all Finder windows have benn processed
					exit repeat
				end if
			end repeat
		end tell
	end tell
end allWindows

It really does work.:slight_smile:

EDITED: to further beat the poor horse.

Finder got an error: Can’t get finder window 1


tell application "Finder"
	activate
	open desktop
	repeat while window 1 exists
		my allWindows()
>		close Finder window 1
	end repeat
end tell

Or:
System events got an error: Connections is invalid.

Marked:


			repeat with rg in radio groups of window 1
				if (radio button "All windows" of rg exists) then
					click radio button "All windows" of rg
					keystroke "j" using command down
					exit repeat
				end if
			end repeat

I badly understand English. An explanation on steps has not understood. After closing all windows Finder, the floating window remains having changed the kind (the section containing radio button " All Windows " will be gone). I copied an example through the buffer of an exchange in ScriptEditor and there started. System 10.3.9

No. It does not work similarly. I observe: opening of a folder, opening of a floating window, closing of a folder, change of a kind of a floating window and its internal information, closing of a floating window, a mistake of performance (close window 1). The second variant of a mistake (connections invalid…) I did not begin to reach repetition.