How to Adjust Column Width in Apple Mail or Finder List View

Hi all,

I am using Apple Mail version 16. Also I am using column layout.

Q: Does anyone have any idea using Applescript or keyboard maestro - how to adjust the column width? So for example the column: from or subject or date received could be wider or narrower by a particular amount?

ALSO IN FINDER…

I am using Ventura version 13.6.7

In Finder, I use: view as list…

Q: Same question as above is there someway to adjust the column width for example : name or date modified or kind etc.?

First thing (and all I know) is double clicking on the column divider bar sets that column to the width of the longest file name in that column. If you option + double click it fits all columns in that window to the longest file name in each column. And then if you option + drag a dividier, it resets all columns to be the same width and you can drag them all to the desired width.

So not really automation, but that’s all the controls I know.

1 Like

Give the last listed script in this discussion a try for Finder.

If that still works, maybe something along the same lines can be achieved with Mail too.

1 Like

Nice I did not know that.

1 Like

Thanks for the info. Well I checked out the page - then I simply went in record in Script editor and it created the code below for Ventura. A good start (the width is dependent on the window size BTW). Next I will look at same for Apple Mail.

tell application "Finder"
	activate
	set current view of Finder window 1 to column view
	set current view of Finder window 1 to list view
	set sort direction of column id name column of list view options of Finder window 1 to normal
	set width of column id name column of list view options of Finder window 1 to 300
end tell

Thanks for your help,

I am Rusty with AppleScript
So, I am looking into scripting with AppleScript for Apple Mail

I went to the script editor and shows open dictionary for Apple Mail.
There are many elements and I did find something related = window

I am quite Rusty with programming AppleScript

  • I did try recording in the script a editor but nothing happened with Apple Mail.

  • I am curious if anybody can help get me started:

  • trying to resize some columns (using column layout) using Apple mail Ventura?
    example mailbox: “MainBox” - columns: From, Subject etc.


window n : A window.
elements
contained by application.
properties
name (text, r/o) : The title of the window.
id (integer, r/o) : The unique identifier of the window.
index (integer) : The index of the window, ordered front to back.
bounds (rectangle) : The bounding rectangle of the window.
closeable (boolean, r/o) : Does the window have a close button?
miniaturizable (boolean, r/o) : Does the window have a minimize button?
miniaturized (boolean) : Is the window minimized right now?
resizable (boolean, r/o) : Can the window be resized?
visible (boolean) : Is the window visible right now?
zoomable (boolean, r/o) : Does the window have a zoom button?
zoomed (boolean) : Is the window zoomed right now?
document (document, r/o) : The document whose contents are displayed in the window.
responds to
close, print, save.

Thanks Dave

I don’t use Apple Mail, so I can’t easily test this, but after a quick search yielded nothing, I chucked an outline for the issue and what I wanted to see in a return into a GPT and it gave me this. Again, give it a try and see if you can get any useful progress from it.


Request

You are an expert in AppleScript and have an in depth knowledge of scripting when it comes to Apple’s platforms and apps. I would like you to draft an AppleScript for me that can set the width of the subject column to a specified value within the Apple Mail app.

Please ensure that you reference the appropriate AppleScript dictionary for the Apple Mail app and that if you take inspiration from any existing scripts online, that you provide a link back to the source in a bullet point following the script definition.

Response

Here’s a sample AppleScript to set the width of the subject column in Apple Mail. AppleScript interacts with the user interface of applications through System Events, and we’ll use this to manipulate the Mail app.

-- Define the width you want to set for the subject column
set desiredWidth to 300

tell application "Mail"
   activate
end tell

tell application "System Events"
   tell process "Mail"
       -- Ensure the Mail window is in the front
       set frontmost to true

      -- Delay to ensure the UI is ready
       delay 1

       -- Find the message list view
       set messageViewerWindow to first window whose subrole is "AXStandardWindow"
       set splitterGroup to first splitter group of messageViewerWindow
       set scrollArea to first scroll area of splitterGroup
       set messageList to first outline of scrollArea

       -- Find the subject column
       set subjectColumn to first column of messageList whose name is "Subject"
       
       -- Adjust the width of the subject column
       set width of subjectColumn to desiredWidth
   end tell
end tell

Notes:

  • AppleScript does not have direct access to modify the width of columns in the Mail app through its dictionary, so this script utilizes the System Events to interact with the UI elements.
  • This script assumes you have enabled access for assistive devices (found in System Preferences > Security & Privacy > Privacy > Accessibility).
  • Adjust the delay if necessary to ensure the UI is ready for interaction.

Sources and Inspiration:

If the notes are correct, then it looks like Mail doesn’t have the same sorts of options as Finder for managing the layout via AppleScript and that UI scripting is your only option on this path.

Again, no guarantees, but maybe it’ll get you far enough along to get something workable.

1 Like

Wow that’s a great idea to try a GPT - I will check it out and let you know.

Well I did try it - but it had errors. So I tried same general thing using Codeium - tried over and over but so far did not get working AppleScript?

I tried a prompt like:

MacOS Ventura - apple mail version 16 and view “use column layout”. Using AppleScript , can you give me a list of the column names in current front most window?

below still has errors - but what i have so far

tell application "Mail"
    set theWindow to front window
    set theColumnNames to {}
    repeat with theColumn in mail columns of theWindow
        set theColumnName to name of theColumn
        if theColumnName is not "" then
            set end of theColumnNames to theColumnName
        end if
    end repeat
    return theColumnNames
end tell

I’ve configured dummy account and had a bit of a play around in Mail with the AppleScript and a poke around with UI Browser, I can get to the point of referencing a column (using slightly different code to what the GPT suggested.

set messageViewerWindow to first window whose subrole is "AXStandardWindow"
set splitterGroup to first splitter group of messageViewerWindow
set subSplitterGroup to first splitter group of splitterGroup
set scrollArea to first scroll area of subSplitterGroup
set messageList to first table of scrollArea
set subjectColumn to first column of messageList

However, at that point, it seems like you can’t just get of set the width of the column to force it to resize.

Poking around a little further I got to this:

tell application "System Events"
	tell process "Mail"
		set frontmost to true
		delay 1
		
		-- Navigate to the specific window
		set messageViewerWindow to first window whose subrole is "AXStandardWindow"
		tell messageViewerWindow
			-- Navigate
			tell splitter group 1
				tell splitter group 1
					tell scroll area 1
						tell table 1
							tell column 4
								-- Get  and set the value of the AXSize attribute
								set columnSize1 to value of attribute "AXSize"
								set value of attribute "AXSize" to 60000
								set columnSize2 to value of attribute "AXSize"
							end tell
						end tell
					end tell
				end tell
			end tell
		end tell
	end tell
end tell

-- Report back
display dialog "The size of column 4 was " & columnSize1 & ", and is " & columnSize2

Now this got me something that I could read but not change … and a bit of experimentation with the layout confirmed it seemed to be the height, not the width of the column.

I went down to the cell level attributes, but I just couldn’t see anything that corresponded to the width of the cell. Only the height once again. And the same thing for the headings (which appear to be a group of sort buttons).

Unless someone has any other suggestions, I think that means you would need to look at the same way you would do it manually. Trigger a click and drag on the column edge to do the resize. And while technically you could do that, I think the resulting automation would end up being rather fragile and overly complex if your window isn’t starting in exactly the same size, position, and layout, every single time.

I had a quick look around to see if there were any particular alternative mail clients that offered more automation of layout, but nothing came up. Little bits about automation for rules and composition, but not so much on the layout.

Hopefully someone else will have an idea for something robust.

1 Like

Thanks so much for looking into this. I like your idea of trying manual clicks and dragging. I will see what else I can try. I’m guessing many people do not use “Column Layout” but I at least prefer it.