A cry for help/Possible OS X Finder or AS bug?

I’ve been working around a strange bug in the Mac OS X Finder with an
AppleScript for quite some time now. Most users don’t notice the bug at all, but
I do. Rather than describe it, follow these steps and see it for yourself:

  1. Make a new Finder window
  2. Set its view style to column
  3. Adjust the column width/s with the slider, making them wider together
  4. Leave the window open and log out
  5. Log back in

At this point, your window will be open, but its columns will be at their
default widths.

  1. Close that window
  2. Open a new Finder window (should default to column view now)

Now, you’ll see your custom widths respected. It just seems to affect the first
window you make or see that’s in column view.

This bothers me, honestly, and I wrote a tiny–and really
dim-witted–AppleScript to get around the problem. Here it is (works best when
run at login automatically):

on run
    tell application "Finder"
        if (count of windows) is greater than 0 then
            -- do nothing
        else if (count of windows) is equal to 0 then
            set fix to (make new Finder window)
            close fix
        end if
    end tell
end run

As I said, it’s not a smart script at all. If you have columned windows open, it
leaves them there for you to deal with. Wanting to make the script smarter, I
came up with this:

on run
    tell application "Finder"
        if (count of windows) is greater than 0 then
            set daWindows to (every Finder window whose current view is column view) as list
            set daStop to 1
            repeat until daStop = ((count of items in daWindows) + 1)
                set reopenMe to item daStop of daWindows
                set helloPath to (target of reopenMe)
                set daPosition to position of reopenMe
                close reopenMe
                set newWindow to (make new Finder window at helloPath)
                set position of newWindow to daPosition
                set daStop to (daStop + 1)
            end repeat
        else if (count of windows) is equal to 0 then
            set fix to (make new Finder window)
            close fix
        end if
    end tell
end run

This works almost as it should. (And it’s probably more complex than it needs
to be.) Where it fails is best described in this manner:

You leave a columned window open to “/Applications/Utilities”, and cycle through
a log out/log in to see the script run. Well, it’ll deal with the window without
closing the non-columned windows, but when the dealt-with window is recreated,
it doesn’t point to “/Applications/Utilities”.

Here’s where I’m stumped. I can’t figure out why the code I wrote doesn’t work,
and I’m starting to think it’s a bug in either the Finder or AppleScript (or
both). Shouldn’t “make new Finder window at helloPath” work after setting
helloPath to “target of reopenMe”?

What, if anything, am I missing?

Any help is appreciated.

-/-
Michael Watson
mike@milesmedia.net
[url=http://www.mikey-san.net/]http://www.mikey-san.net/[/url]

I forgot to mention an earlier posting I did some time ago about a similar failure to set OS9 Finder column widths via scripting. It might be that Apple has transferred this to OS X Finder.

tell application "Finder"
	activate
	set ViewTest to get (container window 1) -- b.v
	set theFolder to folder of ViewTest
	set VT to extended info for theFolder
	set fvc to finder view columns of VT
	try
		set OldVal to size of name of finder view columns of (extended info for (folder of container window 1))
	on error
		display dialog "Front window must be in list view !!" buttons {"OK"} default button 1 with icon 0
		return
	end try
	set size of name of fvc to 200
	apply --catalog info {finder view columns:fvc} to theFolder
	close theFolder
	open theFolder
	set NewVal to size of name of finder  view columns of (extended info for (folder of container window 1))
	display dialog "Old column size " & (OldVal as string) & ", " & return & "Should now be 200 but is: " & NewVal as string buttons {"OK"} default button 1 with icon 1
end tell

→ new value never comes through…
Eelco Houwink

Well, “make new Finder window” is the AppleScript command for the “New Finder Window” command in OS X’s Finder. (It creates a new window at the “computer” level.)

The “target” attribute is where the window is pointing; the file or folder to which the container window leads. Making it “make new Finder window at helloPath”, after setting the helloPath variable, should create a new Finder window that points to/ends at helloPath. It doesn’t, though–but the event log tells me this:

make new Finder window at folder "Utilities" of folder "Applications" of startup disk

It seems like everything should be cool, but I don’t have a window whose target is “Applications Utilities”–just a new window that begins at the so-called “computer” level I’m starting to think the problem is outside/above the script, sitting in the Finder.

-/-
Michael Watson
mike@milesmedia.net