I'm trying to create an AppleScript script that resizes the columns of Finder's list view (e.g. Name, Size …) to their optimal width (i.e. the minimum width where all text in the column is visible) on Mac OS X 10.6. This can be accomplished by double clicking the divider between two column's headers. But I can't find a way to do the same using AppleScript. This is what I've tried:

Finder's column class has the attributes width, minimum width and maximum width but there doesn't seem to be a way to use the width attribute to resize the column to it's optimal width.

I also tried to use UI Scripting to simulate a double click in the small region around the column header divider using the following script:

tell application "System Events"
    tell process "Finder"
        set nameButton to button "Name" of group 1 of outline 1 of scroll area 1 of splitter group 1 of first window

        set {px, py} to position of nameButton
        set {sx, sy} to size of nameButton
        set clickPos to {px + sx, py + 5}

        click at clickPos
        click at clickPos
    end tell
end tell

This should simulate a double click between the headers of the Name column and the column to it's right but it is instead processed by Finder as two distinct clicks on the header of the second column which just changes the sorting order of that column twice.

The Accessibility Inspector also doesn't "see" the small regions around the dividers of column headers and always shows the properties of either column header.

Is there any other way to accomplish this?

1 Answer 1


The only thing that I can think of off the top of my head would be to get a list of the items in the current folder, find the item with the longest name, and then resize the width per that value. That's really all that's happening with the optimal width double-click.

  • I also thought about that as a last resort but for this I'd need a reliable way to get the exact length in pixels for each string in the list and I'd have to handle stuff like indentation because of opened subfolders. Jul 19, 2012 at 15:44
  • I don't think you'll ever get that via Applescript. It really isn't intended for that level or type of detail. The only way you would get the exact pixel dimensions of a string would be to create an actual Cocoa application in Xcode using CoreGraphics. Jul 19, 2012 at 17:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .