Finder View Options: Always Open in . . .

Greetings, folks!

In the endless effort to get Finder to be consistent :slight_smile: , I would like to know just where the View Options attribute “Always open in icon/list/column view” is stored. It is not in the “.DS_Store” file (AFAICT), but it has to be stored somewhere, it is a consistent folder property!

Does anyone know just where this value is stored and if there is any way I can access this value and enable this to always open in icon/list/column view?

Thanks!!

Model: 2.33GHz MBPC2D
Browser: Firefox 3.6b5
Operating System: Mac OS X (10.6)

Here is something to help you out:

-- List View  => Nlsv
--Column View => clmv
-- Icon View => icnv
-- Flow view => Flwv (available only in leopard/snow leopard)

set theOptions to {"Nlsv", "clmv", "icnv", "Flwv"}

set YOURCHOICE to random number from 1 to 4 -- this is not really consistent so insert the right thing here
do shell script "defaults write com.apple.finder FXPreferredViewStyle -string " & item YOURCHOICE of theOptions

-- restart the "finder"
try
	tell application "Finder" to quit
	delay 1
	activate application "Finder"
on error
	try
		do shell script "killall Finder"
	end try
end try

PS: The path to the preference file of the Finder is ‘~/library/preferences/com.apple.finder.plist’

hope it works,
ief2

Thanks, ief2! Unfortunately, the com.apple.finder FXPreferredViewStyle setting doesn’t control the Finder View Options "always open in . . . " setting, but I appreciate your effort!

(The Preferred View Style setting also gets changed, errantly, by the Finder whenever a folder is changed. :wink: I have a script that corrects it on a regular basis.)

There must be some place where that elusive, Finder View Options: Always Open in . . . setting gets stored, separately for each folder!

.DS_Store files contain this information

Thank you, Craig, but that was the first place I looked (as noted in the first post).

More specifically, I opened two identical .DS_Store files (one with and one without the "Always open in . . . " checkbox checked) in BBEdit and in HexEdit and there was no difference between the two files. There was also no resource fork in the files, so the setting couldn’t be hiding there. Property List Editor wouldn’t open them at all.

If the data is stored in the .DS_Store (as would make most sense), where is it?

Thank you!

Bump.

(Sorry to be a pest! :wink: )

Blessings and Happy New Year!!

Greetings, folks!

Please allow me to offer the best solution (AFAICT) to the “Always Open in xyz View” issue. (I use this to force windows to always open in list view, but of course, it can be changed.)

I have learned that the “.DS_Store” file (in every folder) is a proprietary format that Apple voraciously defends. It has been reverse engineered over the years, but I am not aware of anyone ever having been able to make it possible to reliably edit the file. Thus the appended script (which is a poor substitute, but is relatively fast–for a GUI script–and operates without any mouse movement).

FYI, I have also included the script that I use to position and format folder windows that calls it and a script that automates the process for all folders within the frontmost folder.

The three scripts appended below are:
Always Open in List View
Position and Zoom Window
Position and Zoom All Windows

Thanks for your patience on this, perhaps this may be useful to someone. I have used variations of the last two scripts for decades. (Any suggestions for cleaning up a newbie’s script are always appreciated! :wink: )

Blessings,

Richard Fairbanks


Always Open in List View

tell application "System Events" to tell process "Finder"
	set frontmost to true
	if menu item "Show View Options" of menu "View" of menu bar 1 exists then click menu item "Show View Options" of menu "View" of menu bar 1
	repeat with i from 1 to the number of windows
		if the description of window i is "system floating window" then
			set the focused of window i to true
			if the value of (item 4 of (the value of item 7 of the attributes of window 1 as list)) is 0 then ¬
				click (item 4 of (the value of item 7 of the attributes of window 1 as list))
			exit repeat
		end if
	end repeat
	click menu item "Hide View Options" of menu "View" of menu bar 1
end tell

Position and Zoom Window

global theFolder, xOffset, yOffset, sourceXOffset, sourceYOffset, constantXOffset, constantYOffset, screenHeight, constantWidth, noScrollBar

set sourceXOffset to 2
set sourceYOffset to 46
set constantXOffset to 22
set constantYOffset to 22
set constantWidth to 828
tell application "Extra Suites" to set screenHeight to (item 2 of ((ES screen info) as list))
set alreadyOpen to true
set noScrollBar to 0

activate application "Finder"
tell application "System Events" to tell process "Finder"
	-- return the description of window 1
	if the description of window 1 is "system floating window" then click menu item "Hide View Options" of menu 1 of menu bar item "View" of menu bar 1
end tell

tell application "Finder"
	-- return the properties of window 1
	if the name of window 1 is "New Search" then -- if it is a search window
		set the properties of window "New Search" to {bounds:{800, 46, 1440, 900}, sidebar width:0}
	else if the class of window 1 is window then -- if it is a text clipping
		run script alias "HD:Users:me:Scripts:Finder:Center Quote Window"
	else if the name of the front Finder window is "Trash" then
		run script alias "HD:Users:me:Scripts:Finder:Open the Trash Folder"
	else
		my setWindow()
		set theFolder to the folder of the front Finder window
		my (setPosition for theFolder)
		run script alias "HD:Users:me:Scripts:Finder:Always Open in List View"
	end if
end tell

on setWindow()
	-- tell application "Finder" to tell window 1 to return properties of columns of list view options -- doesn't work
	-- tell application "Finder" to return properties of columns of list view options of window 1 -- works
	tell application "Finder" -- as per the above two examples, the words "of window 1" must be in each line. (why?)
		set statusbar visible of window 1 to true
		set the current view of window 1 to list view
		set properties of column name column of list view options of window 1 to {index:1, sort direction:normal, width:300}
		set properties of column size column of list view options of window 1 to {index:2, sort direction:reversed, width:100}
		set properties of column modification date column of list view options of window 1 to {index:3, sort direction:reversed, width:160}
		set properties of column kind column of list view options of window 1 to {index:5, sort direction:normal, width:220}
	end tell
end setWindow

to setPosition for theFolder
	tell application "Finder"
		tell theFolder to try -- this needs to be on a separate line
			tell container window
				set alreadyOpen to class is Finder window
				open
			end tell
		end try
		
		--calculate the offset multiplier	
		set thePath to theFolder as string
		set offsetMultiplier to ((the number of items in (find text ":" in thePath with all occurrences)) - 1)
		set xOffset to (sourceXOffset + (constantXOffset * offsetMultiplier))
		set yOffset to (sourceYOffset + (constantYOffset * offsetMultiplier))
		
		set the calculates folder sizes of the list view options of the front Finder window to true
		
		tell the container window of theFolder to try
			set toolbar visible to false -- this doesn't seem to be needed to be toggled with 10.6; it was also used again if too tall
		end try
		
		tell the front Finder window
			set the position to {xOffset, yOffset}
			
			-- the following was modified into an "if" statement as it seems possible in 10.6.1 to avoid calling if not necessary
			if the zoomed is false then my zoomWindow()
			
			-- if zooming it still leaves the vertical scroll bar showing
			tell application "System Events" to tell window 1 of application process "Finder"
				if scroll bar 1 of scroll area 1 of splitter group 1 exists then set noScrollBar to 1 -- this is if any scroll bar exists
			end tell
			
			if noScrollBar is 1 then -- if any scroll bar still exists then fix it
				set the bounds to {xOffset, yOffset, xOffset + 200, yOffset + 100}
				my zoomWindow()
			end if
			
			--check to see that zooming it hasn't bumped it up out of position
			set thePosition to the position
			set windowTop to (item 2 of thePosition)
			
			-- if the folder is too tall to fit in its position then reduce its height
			if (windowTop < yOffset) then set the bounds to {xOffset, yOffset, (xOffset + constantWidth), screenHeight}
		end tell
		
		tell theFolder
			tell container window to try
				if not alreadyOpen then close
			end try
		end tell
	end tell
end setPosition

on zoomWindow()
	tell application "System Events" to tell process "Finder"
		tell window 1 to repeat with i in (buttons)
			if value of attribute "AXSubrole" of i is "AXZoomButton" then
				click i
				exit repeat
			end if
		end repeat
	end tell
end zoomWindow

Position and Zoom All Windows

-- tell application "System Events" to set visible of process "Finder" to false -- doesn't allow Finder to set folders when hidden!
tell application "System Events" to set visible of process "Smile" to false -- if it is being run from Smile, which works for me!

tell application "Finder"
	activate
	-- the following line sets the front folder, within which all folders get processed
	run script alias "HD:Users:me:Scripts:Window Tiling:Position and Zoom Window"
	try
		set theFolders to (every folder in the entire contents of the folder of the front Finder window) as alias list
	on error -- if there is only one folder, each of the following work, with no folders, an error will still result
		-- set theFolders to (every folder in the entire contents of the folder of the front Finder window) as alias as list
		set theFolders to {(every folder in the entire contents of the folder of the front Finder window) as alias}
	end try
	set theFolderCount to count theFolders -- this is so the Finder only counts them once!
	say "there are " & theFolderCount & " folders to process"
	-- return theFolderCount -- this is handy for checking the number of folders in advance of a run
	set theCycle to 0 -- so we can announce the progress every 50 windows (or whatever is chosen below)
	with timeout of (12 * hours) seconds -- this allows for twelve hours”it may need to be increased!  ;-)
		repeat with i from 1 to theFolderCount
			set theCycle to (theCycle + 1)
			if theCycle = 50 then
				say i
				set theCycle to 0
			end if
			open item i of theFolders
			run script alias "HD:Users:me:Scripts:Window Tiling:Position and Zoom Window"
			close window 1
		end repeat
	end timeout
end tell

say "Done processing folders. Be sure to log out!"