Please, a script for finder view options!

I was wondering if anyone here could help me. I have been looking everwhere for an applescript that will change the view settings for ALL the folders on my hard drive to the same settings, or to the all windows setting, so I can easily just have the “All Windows” setting be what I want it to be…

The script would have to change the view setting of the selected folder and all of it’s subfolders to icon view, 64x64 icon size, and arranged by name… I’ve tried tp write it myself and modify other people’s scripts to find my needs, but I can never seem to get it right… I know it’s gotta be so simple but I just can’t seem to get it right (I do have some small knowledge of applescript but still very little. Please help me!

Hi, deej5871.

There are many thousands of folders on a typical OS X partition, most of which you’re never going to open. It’s probably not worth changing the view settings of all of their windows. If you do want to set all the window views in a particular hierarchy, here is one possibility. It set the views to icon view, 64 x 64 icons, arranged by name. On my G3 400, it handles a duplicate of my user Library (577 folders) in about 56 seconds:

property counter : 0

on open theFolders
	set t to (current date)
	set counter to (count theFolders)
	tell application "Finder" to activate
	-- Do the business with each dropped folder
	repeat with thisFolder in theFolders
		setViews(thisFolder)
	end repeat
	set t1 to (current date) - t
	tell application "Finder" to display dialog (t1 as string) & " seconds for " & counter & " folders." with icon note
end open

on setViews(thisFolder)
	tell application "Finder"
		tell (get thisFolder's window)
			set its current view to icon view
			tell its icon view options
				set {icon size, arrangement} to {64, arranged by name}
			end tell
		end tell
		try
			set theSubfolders to every folder of thisFolder as alias list
		on error
			set theSubfolders to first folder of thisFolder as alias as list
		end try
	end tell
	set subfolderCount to (count theSubfolders)
	if subfolderCount > 0 then
		set counter to counter + subfolderCount
		repeat with i from 1 to subfolderCount
			setViews(item i of theSubfolders)
		end repeat
	end if
end setViews

If you want the windows re-zoomed as well, you have to open them first. The following script does exactly that. It has the disadvantage of taking about 426 seconds to handle my 577-folder hierarchy, but at least you can see that something’s going on. And it’s quite pretty to watch. :slight_smile:

property counter : 0

on open theFolders
	set t to (current date)
	set counter to (count theFolders)
	tell application "Finder"
		activate
		-- Make a note of what windows are currently open...
		set openFolders to folder of every Finder window
		-- ... and close them
		close every Finder window
		delay 1
		-- Do the business with each dropped folder
		repeat with thisFolder in theFolders
			open thisFolder
			my setViews(thisFolder)
		end repeat
		-- Reopen the windows that were open before
		open openFolders
	end tell
	set t1 to (current date) - t
	tell application "Finder" to display dialog (t1 as string) & " seconds for " & counter & " folders." with icon note
end open

on setViews(thisFolder)
	tell application "Finder"
		try
			set theSubfolders to every folder of thisFolder as alias list
		on error
			set theSubfolders to first folder of thisFolder as alias as list
		end try
	end tell
	set subfolderCount to (count theSubfolders)
	if subfolderCount > 0 then
		set counter to counter + subfolderCount
		tell application "Finder"
			open theSubfolders
			tell every Finder window
				set its current view to icon view
				tell its icon view options
					set {icon size, arrangement} to {64, arranged by name}
				end tell
				set its zoomed to true
				close
			end tell
		end tell
		repeat with i from 1 to subfolderCount
			setViews(item i of theSubfolders)
		end repeat
	end if
end setViews

Thank you! I realize that I probably won’t be accessing every folder on my hard drive, it’s so annoying when I’m doing something and there’s a folder that’s all 32x32, completely unorganized, and I don’t won’t to deal with it… I know, I’m weird like that…

A couple of nice scripts Nigel, my compliments and many thanks.

NG, I used the first script to reset all of my folders to list view – I commneted out some parts and changed the icon view to list view, which I 've always preferred. Anyhow, I thought you might like to see the numbers…

Here’s the part I changed with the part I commented out.

			set its current view to list view -- change from icon view
			--tell its icon view options
			--set {icon size, arrangement} to {48, arranged by name}
			--end tell

PID COMMAND %CPU
745 Finder 18.8%
823 listview.app 12.1% (this is your script)

The above were the highest %CPU numbers I caught, it was usually a lot lower. I seen PID 823 @ 2.2% at one point, but the Finder spiked up to about 26% at that same point.

At the end the dialog displayed “2881 seconds for 15164 folders”. Ran on a G4 450X2 MHz, 7200MHz 60 gig HD 63% full, 768 MB Ram. Pretty cool script, it chugged right along without any errors utilizing both processors. Thanks again.

My pleasure. :slight_smile: I forgot to mention that the two scripts are droplets and are meant to be saved as applications. (In case you hadn’t realised.) You drag the target folder(s) onto their icons.

Well, there’s always this quick fix, which could go in your script menu: :slight_smile:

tell application "Finder"
  tell the front Finder window
    set its current view to icon view
    tell its icon view options
      set {icon size, arrangement} to {64, arranged by name}
    end tell
    set its zoomed to true
  end tell
end tell

Hi, Greg. Thanks for the feedback. When originally testing the scripts, I had to use different settings for the return runs, as it were. I found the re-zooming version to be slightly faster when scaling down than when scaling up. I’ll study your figures again more closely when I’m off-line. Thanks again. :wink:

Hi all :slight_smile:
Processing really interesting for scripting…
Well, here another possibility, with the property “entire content” of the Finder, which I think is faster than a recursive routine… (the tests which I have just made seem faster):

on run
	tell me to open ({} & (choose folder))
end run

on open Lst
	tell application "Finder"
		try
			
			set {Avant, LstW} to {(current date), {}}
			repeat with Itm in Lst
				if last character of ("" & Itm) is in {":", "/"} then
					try
						set LstW to LstW & ((folders of entire contents of Itm) as alias list) & (Itm as alias)
					on error
						set LstW to LstW & ((folders of entire contents of Itm) as alias) & (Itm as alias)
					end try
				end if
			end repeat
			
			repeat with ItmW in LstW
				tell window of folder ItmW to set properties of it to ¬
					{current view:icon view, icon view options:{icon view options:¬
						{arrangement:arranged by name, icon size:64}}}
			end repeat
			
			set Duree to (current date) - Avant
			display dialog "Finished processing..." & return & return & ¬
				"Folders :  " & (length of LstW) & return & ¬
				"Time :  " & Duree & " seconds" & (beep) with icon 1
			
		on error mer number ner
			if ner is not -128 then ¬
				display dialog "" & ner & " : " & mer & (beep 2) with icon 0
		end try
	end tell
end open

This solution cannot be to use on another old version of the system, because “entire content” had a big bug, which seems to be solved under OsX…
:wink:

Hi, Fredo.

I did consider using ‘entire contents’, knowing that it had been largely fixed in OS X. But - rightly or wrongly - I still instinctively distrust it. deej5871 was talking about treating all the folders on his hard drive, so I decided not to take any chances.

When I tried out your script on my test hierarchy, it reported the correct number of folders and was very fast indeed! Unfortunately, the speed turned out to be due to the fact that it wasn’t actually doing anything with the window settings. :frowning:

The culprit seems to be this section:

I’ve changed it to:

repeat with ItmW in LstW
  tell (get window of ItmW) to set {current view, arrangement of its icon view options, icon size of its icon view options} to ¬
    {icon view, arranged by name, 64}
end repeat

… and the script now works perfectly and is still ten seconds faster, on my machine, than my recursive version. (46 seconds as opposed to 56 seconds for 577 folders.) :slight_smile:

Hi, Greg.

I’ve now looked at this more closely and have to admit I don’t understand what these figures mean. Presumably they’re something to do with processor usage, but I’m not sure. Could you please explain what they are, and what constitutes good and not so good? :slight_smile:

Hi Nigel :slight_smile:

Yes, me also, I am a little being wary, but I must recognize that until now, on all my tests, I did not find any problem… then I think that we can again (finally I would say) use this property without using any other OSAX.

Indeed, I am also of your opinion.

Oups… very curious, since in my machine (OsX 10.2.6) that work very well… but I recognizes that I did not do much test (it was very late yesterday :? )…

However, after having tested other syntaxes, this one seemed to work without problem… curious…
Do you think that this difference would come from the different configurations between your machine and mine? :?:

Thanks Nigel :), but I cannot test it for this moment (I am in my job), I would see this evening (at France evining ;))

Yea… very nice !!! (even if it is not a so great difference… we are on the right way :smiley: :wink: )

Thank you very much Nigel :smiley:

I’ve tried both versions of the script (Nigel’s and Fredo’s) and they both work quite nicely. I wonder why Fredo’s version doesn’t work for you, Nigel. I should note that I modified the scripts slightly to set the windows to list view.

[OS X 10.2.8]

– Rob

Well, I’ve gone back for a second look. On my machine, Fredo’s original syntax does in fact change list views to icon views (or vice versa, if so adjusted), but it won’t change either the icon view options or the list view options.

I updated to 10.2.8 last week, but this shouldn’t make any difference. The Finder’s 10.2.1 in any case. (Or claims to be!)

A variation of the ‘properties’ approach which does work for me is:

repeat with ItmW in LstW
  tell window of folder ItmW
    set its properties {current view:icon view}
    set properties of its icon view options to {arrangement:arranged by name, icon size:64}
  end tell
end repeat

22 seconds for my 577 folders. Very nice. :slight_smile:

Oops!

repeat with ItmW in LstW
  tell window of folder ItmW
    set its properties to {current view:icon view} -- NB. 'to'
    set properties of its icon view options to {arrangement:arranged by name, icon size:64}
  end tell
end repeat

You could also take a look at Finder Window Manager for even more options.

Jon

Hi Nigel and all :slight_smile:

Yea… after some tests, you are right, the syntax which I proposed did not work completely… :? :cry: :wink:

This syntax it is OK for me too… :smiley:

Yea :smiley: … and here my test (OsX 10.2.6 - G4 1.25 GHz) :wink:

Thanks…

Actually, I tried Finder Window Manager, but I got some problems with the “Parent Cloner” feature (which was the only thing I could find anywhere on the internet that did what I wanted, if there is another feature that was supposed to do what I wanted, be my guest)… First of all, it took a long time, while Nigel’s script did it in a much shorter time (I forgot it exactly). The second problem was that it did set the arrange the folder and made the icons the right size, but it didn’t actually set the view options. Meaning: if I deleted a file in the folders modified by Finder Window Manager, the other files would stay in the same spot, not snap to the right arrangement…

Sorry, I don’t mean to bash, those were just some problems I encountered with the program.