MacOS – Is it possible to change a Finder List View column width in AppleScript

applescriptautomationfindermacos

I want to create an AppleScript that opens five predefined folders in five different tabs in one new Finder window with predefined bounds and then shifts the active tab of this window to tab one. I would also like the full filenames (of the files in all five folders) to be displayed without any truncation. I exclusively use List View in Finder.

Can this last condition be accomplished in AppleScript or automated in any way?

The default "Name" column width is too narrow; the full filenames of my files are always cut off. To fix this, every time that I open any folder, I have to either manually drag the "Name" separator dramatically to the right or double-click on the separator itself (which automatically adjusts the width to show the longest entry in full).


My understanding is that it is impossible to change the default width of the List View "Name" column on a Mac. Otherwise, I could simply set the default width of this column to be larger and this width would be set as the default across all folders.

  • Holding down the option ⌥ key while dragging a column separator (to save its width) is fruitless.

  • I tried setting the wider column size as the default by pressing command ⌘ + J in Finder & selecting "Use as Defaults." But, this did not work.

  • I tried increasing every "Name" width value in my com.apple.finder.plist file and then re-saving the file, as described in the most recent comment by user azeotropo (from 2012) of this webpage (from 2003). But, the old, narrow "Name" width remains.

OS X El Capitan, version 10.11.6.

Best Answer

The answer to the subject of your question "Is it possible to change a Finder List View column width in AppleScript?" is YES. The answer to your question about using AppleScript to set the width of the name column to be big enough to display the names without truncating is also yes. I am not sure how to handle the tabs in the Finder window but it sounds as if you have a script that addresses the tabs already.

One big surprise (to me) was that I had to close and re-open the Finder window in order to see the change.

Here is a script that operates on the frontmost Finder window. The width of the "Name" column is set to be 7.5 * (number of characters in the longest name in the window). It is not the perfect width but it works for me as long as I'm using 12-point text in the Finder. We are setting the width of the column to a certain number of pixels, and each character takes a different number of pixels since the Finder is not using a fixed-width font, so we can't be exactly right when setting the width. But 7.5 * the number of characters in the longest name seems to work pretty well. You can adjust it of course.

tell application "Finder"
    activate
    set the_window to window 1
    set current view of the_window to list view
    set the_options to list view options of the_window
    set the_name_column to first column of the_options whose name is name column
    set the_items to name of every item of the_window
    -- get the longest name (count of characters)
    set longest_name to 0
    repeat with I from 1 to count of the_items
        --check for invisible files, which we don't need to consider
        if character 1 of item I of the_items is not "." then
            if (count of characters of item I of the_items) > longest_name then
                set longest_name to count of characters of item I of the_items
            end if
        end if
    end repeat
    -- this only works if the text size is 12. The multiplier 7.5 could be changed
    -- if the text size is something else. 
    set desired_width to longest_name * 7.5
    set width of the_name_column to desired_width
    -- we have to close and reopen the window in order to see any changes.
    -- there might be a "refresh window" command but I don't know it.
    set the_target to target of the_window
    close the_target
    open the_target
end tell