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.

  • As far as I know, it can be automated by dragging the mouse ;) not sure if that's what you'd like, though. – Skeleton Bow Mar 12 '17 at 11:00
  • Yeah, I've been trying to work out an AppleScript solution that involves mouse clicks. However, I cannot get it to work properly because code-based mouse clicks are very finicky and unreliable. – rubik's sphere Mar 12 '17 at 13:38

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"
    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
  • I appreciate the reply, but it seems that set width of column does not do anything on El Capitan (10.11.6). – rubik's sphere May 5 '18 at 22:10
  • I will have a look at 10.11.6 and get back to you. – Christian Boyce May 6 '18 at 3:52
  • I tested the script on a Mac with 10.11.6 and it worked for me. Try making the Name column very wide (much wider than you need) and then running my script. You should see the window close, then open again with a resized Name column. It should be obvious then that the width has changed. – Christian Boyce May 6 '18 at 5:08
  • Here is a gif that shows what happens when I follow your suggestion; the column width still does not widen at all. – rubik's sphere May 6 '18 at 10:07
  • Your gif is very helpful-- thank you. I think that in your example you have an item with such a long name that my script breaks down. There may be a limit to how wide a column can get with respect to the total window width. Try it with a less extreme case and you should see it work. Then, between us, we should be able to handle the extreme cases. – Christian Boyce May 7 '18 at 0:51

This following code will set the name column, in list view, to fit the size of the longest filename in either every open window or every tab in every window in Finder app. If no finder windows are open, it will open a new finder window in list view and set the name column width appropriately

This code requires the “Cliclick” is short for “Command-Line Interface Click”. It is a a tiny shell/Terminal application that will emulate mouse clicks or series of mouse clicks (including doubleclicks and control-clicks) at arbitrary screen coordinates. Moreover, it lets you move the mouse, get the current mouse coordinates, press modifier keys etc., Which is free for download and easy to install.

On my system I have. cliclick in the following directory: /usr/local/bin/cliclick. Because of this location, in my AppleScript code and in Terminal app, I need to use the full path to cliclick to call the command. For example: do shell script "/usr/local/bin/cliclick rc:." In AppleScript is telling cliclick to right-click.

This works for me using the latest version of macOS Mojave.

The x and y coordinates used in this following script were set while my display resolution was at 1280 x 800

global thisWindow

tell application "Finder"
    if not (exists of Finder window 1) then
        make new Finder window to path to documents folder
    end if
    set theWindows to name of windows
    repeat with i from 1 to count of theWindows
        set thisWindow to item i of theWindows
        set index of Finder window thisWindow to 1
        tell its Finder window thisWindow
            set currentView to current view
            if currentView is not list view then
                set current view to list view
            end if
        end tell
        my setColumnWidth()
    end repeat
end tell

on setColumnWidth()
    tell application "System Events"
        repeat while not (exists of scroll area 1 of splitter group 1 of splitter group 1 ¬
            of window thisWindow of application process "Finder")
            delay 0.1
        end repeat
        set frameBounds to value of attribute "AXFrame" of UI element 2 of row 2 ¬
            of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 ¬
            of window thisWindow of application process "Finder"
    end tell

    set x to (item 1 of frameBounds) - 1
    set y to (item 2 of frameBounds) - 13

    do shell script "/usr/local/bin/cliclick dc:" & x & "," & y -- Double Click At Coordinates
end setColumnWidth

enter image description here

enter image description here

  • Interesting but in my testing under macOS High Sierra it failed a number of times in testing, enough that I can't +1 it. BTW I'd add the -r option to the cliclick command to "Restore initial mouse location when finished". – user3439894 Oct 25 '18 at 2:22
  • Using macOS High Sierra, Just curious exactly where the script is getting jammed up. In my version of the script I have it set to restore the original mouse location. I omitted that because It did not seem useful since I was running it through a service menu...Which would have been the last mouse location I will make the update shortly – wch1zpink Oct 25 '18 at 2:32
  • While it will work on a Finder window nonetheless, it sometimes actually clicks on a different application window with unwanted consequences. Too late tonight for me to try and debug it, but will tomorrow if I get a chance. – user3439894 Oct 25 '18 at 2:33
  • I really don't have the time to debug this however, I did play with it some more and continue to get undesired results with the click actually not clicking the Finder window but another application window and also when I have more then one Finder window open and on different Desktops, while one of the windows gets it name column expanded, the one on the current Desktop, it then switches to the other Desktop. Why, who knows!? Bottom line is, while it works for you in your environment it's way too buggy in my environment and am seriously considering down-voting this answer because to it. – user3439894 Oct 25 '18 at 14:37

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.