Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Set 'All Windows' and other view options via AppleScript Desktop
After reinstalling my system recently, I had a look at the mess my windows had turned into, and started looking into AppleScript as a means to set my windows to my preferred view settings. As it turned out, there was no easy way to set the "All Windows" option -- the only scriptable commands in Finder applied to "This Window Only" settings. Then I learned about GUI Scripting, and after a couple days of trial and error I got the thing to work reliably -- here's the code.

What the script does:

You can either drop items into it or open it, in which case you will be prompted to open a folder. At the start, Finder is activated, all Finder windows are closed, and the "Show View Options" window is opened. The script also stores the username of the current user, which it needs for checking read rights for folders.

The script processes both disks and folders recursively. Each disk or folder is set to icon view, opened, moved and resized, and the sidebar width is set. Then the "This Window Only" icon view options are set to my defaults. Then "All Windows" is set for icon view options. Next, the "This Window Only" list view options are set to my defaults, and finally, "All Windows" is set for list view options. Last of all, the zoom button is clicked, which resizes the window. After all disks and folders have been processed, a dialog box is shown stating the number of folders/disks processed.

Note that you should not do anything else on the computer while the script is running. The script depends on the Finder windows remaining in a certain order, and Finder must stay active. If you do want to stop the script, close any window, and the script will harmlessly crash, displaying an error message. Note that the script takes a long time to run: in my tests, processing 300 folders took about an hour.

If anyone wants to modify the script for their own settings, feel free to do so. But before you start messing around, I should explain a few things so you can avoid some of the worst pitfalls.

First: checking read access. The script must be able to open a folder to change its view options. Therefore, you need to have read access. The script checks if either the owner or the group equals your username and if either of them or all users have read access. It is of course possible that the group name does not equal your username and you are a member, but this was quite enough complex as it is.

Second: checking file type. I did find a simple check to identify folders, but it did not work in all cases. Note that applications and certain files are considered folders, as they can have their own contents. This is why you must check the exact class of the item to be sure only normal folders and disks are processed.

Third: aliases should not be processed. The class of an alias is the same as the class of the original, so you need to check for an alias separately. With aliases, you could easily make file hierarchies which would result in the script processing folders several times or getting in infinite loops. Therefore, aliases are not touched.

Fourth: setting the "All Windows" setting. This is done in both icon and list view modes with GUI scripting. This is the part that requires every window to be opened, which also makes the script slow. Here you may notice that the action is click radio button 1 of radio group 1 of window 1. window 1 is the window on top, which is always the "Show View Options" window. radio group 1 is the group of radio buttons, and radio button 1 is the button labeled "All Windows." But this is not always so. The "Show View Options" remains open as the script is running, and its contents change as the windows are opened and closed and their view modes change. Depending on what the last displayed view mode was, the index of the radio group may change.

Let's illustrate this with an example. At first, before a window is opened, the "Show View Options" window shows options for the Desktop. Then, a window is opened. If the window was opened first before setting its view mode it could be in any mode, and the "Show View Options" window would change accordingly. So, if you open a window which is already in icon view as it is opened, then the radio group of the "All windows" radio button is number 1. If it was in list view and then changed into icon view, the number would be 3, because the previous view was not the Desktop but list view. The above script only works because the views follow in a fixed order: first Desktop, then open a folder already in icon view, change to list view, close, again Desktop. So if you change the processing order, the number of the radio group is probably going to change too.

Fifth: zooming the window. button 2 of window 2 is always the zoom button of the window below the "Show View Options" window. No way to go wrong here.

There's my take ... I could not find any script that would do this for me, so I had to make this myself. I did find plenty of questions on how to set the "All Windows" setting, which suggested that this might be useful. Hope it is!

[robg adds: I haven't tested this one.]
  • Currently 2.33 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)

Set 'All Windows' and other view options via AppleScript | 1 comments | Create New Account
Click here to return to the 'Set 'All Windows' and other view options via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Set 'All Windows' and other view options via AppleScript
Authored by: deathtoll2001 on Jul 20, '07 06:46:20AM
I did some looking around, as it seemed like there had to be SOME better way to go about mass options-settings, and I found A built in method over at macworld. There's a program in your applications folder called "Automator" and it can be used to set options for certain sets of folders, and can be added as a plug-in to your finder menus as well.

[ Reply to This | # ]