6

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.

2
  • As far as I know, it can be automated by dragging the mouse ;) not sure if that's what you'd like, though.
    – Oion Akif
    Commented Mar 12, 2017 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. Commented Mar 12, 2017 at 13:38

2 Answers 2

3

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
14
  • I appreciate the reply, but it seems that set width of column does not do anything on El Capitan (10.11.6). Commented May 5, 2018 at 22:10
  • I will have a look at 10.11.6 and get back to you. Commented May 6, 2018 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. Commented May 6, 2018 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. Commented May 6, 2018 at 10:07
  • 1
    Good news! I typed the following command in Terminal, rm ~/Library/Preferences/com.apple.finder.plist (source), followed by killall Finder (source), and your script now works. Is it possible for the script to work for longer filenames? I ask because most of my filenames are long. Commented May 8, 2018 at 14:51
2

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 third-party utility, Cliclick.

“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.

It's free to download but it's donationware, and is easy to install.

On my system I have cliclick in the following directory: /usr/local/bin/. 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"
    activate
    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

4
  • 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". Commented Oct 25, 2018 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
    Commented Oct 25, 2018 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. Commented Oct 25, 2018 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. Commented Oct 25, 2018 at 14:37

You must log in to answer this question.

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