Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript to change the all column widths in Numbers

Hi - can someone help provide an Applescript that changes the value of all column widths?


I have the below code working which changes the width of one column, but ideally I'd like to change the value of all columns. Any help is much appreciated!


tell application "Numbers"	
	tell table 1 of sheet 1 of document 1
		set width of column 1 to 100
	end tell

Posted on Jun 17, 2021 2:07 PM

Reply
Question marked as Best answer

For the automation to be worth it you would want to make the script reusable on different tables and documents and be able to specify the width you want.


Here's a script that enables you to select any table and set the width of all its columns with one click. It will ask you what width you want.


For easy access from any Numbers document you can put it in the script menu.


SG


set theWidth to text returned of (display dialog "Width to make all columns" default answer "100" buttons "OK" default button 1)
tell front document of application "Numbers"
	tell active sheet
		tell (first table whose class of selection range is range)
			set width of every column to theWidth
		end tell
	end tell
end tell



Usage:


  1. Copy-paste to Script Editor (in Applications > Utilities)
  2. Click a cell in any table and click <run>


(If "nothing happens" make sure Script Editor is listed and checked at System Preferences > Security & Privacy > Privacy > Accessibility)

Posted on Jun 17, 2021 8:23 PM

Similar questions

7 replies

Jun 17, 2021 5:32 PM in response to adrian-201

I think you can change it quicker by selecting column A by single clicking the "A" at the top of column A, then scroll to the right so you can see the last column,


then hold the shift key and single click the last to column. This will select all columns.


then open the table formatter:



Then change to width for all selected columns as needed

Jun 17, 2021 6:26 PM in response to adrian-201

This AppleScript will do what you want:


tell application "Numbers"
	tell table 1 of sheet 1 of document 1
		set width of every column to 100
	end tell
end tell


Once the script is written, it takes just one click––noticeably faster than selecting the columns and going to the panel at the right to input a value.


SG

Jun 17, 2021 7:59 PM in response to adrian-201

Hi Adrian,


A small variation on Wayne's solution:


Wayne's instructions start with the column and row reference tabs showing, meaning at least one cell in the table is already selected.


Instead of clicking the tab for Column A, then scrolling to the last column of the table and shift-clicking it to expand the selection to 'all columns,' use one of these methods to expand the selection to the whole table:


Click the 'bullseye' circle at the intersection of the column and row reference tab lists to select the Table (and all of its columns), or

Press command-A to expand the selection to 'All cells in the table'.


Then go directly to the Table Inspector, select the Column Width control and set it to the size you want.


Regards,

Barry

Question marked as Best answer

Jun 17, 2021 8:23 PM in response to adrian-201

For the automation to be worth it you would want to make the script reusable on different tables and documents and be able to specify the width you want.


Here's a script that enables you to select any table and set the width of all its columns with one click. It will ask you what width you want.


For easy access from any Numbers document you can put it in the script menu.


SG


set theWidth to text returned of (display dialog "Width to make all columns" default answer "100" buttons "OK" default button 1)
tell front document of application "Numbers"
	tell active sheet
		tell (first table whose class of selection range is range)
			set width of every column to theWidth
		end tell
	end tell
end tell



Usage:


  1. Copy-paste to Script Editor (in Applications > Utilities)
  2. Click a cell in any table and click <run>


(If "nothing happens" make sure Script Editor is listed and checked at System Preferences > Security & Privacy > Privacy > Accessibility)

Jun 18, 2021 6:42 AM in response to adrian-201

adrian-201 wrote:

Thanks so much SG - this is incredibly helpful!

Any clue how to get this to work without having to click a cell first? Just to make automating all that more smoother, would be great if the script worked without having to click a table first 😄


That can easily be done. But how do you want to tell it which table? Clicking in a table first is a simple way of designating the table you want to change.


If you want it to always change the first table on a sheet then you could simply change


tell (first table whose class of selection range is range)


to


tell table 1



You could also have the script present you with a list of tables on that sheet, from which you could choose.


I find it simpler to just click a table before running the script it can be adapted to pretty much however you want it to work.


SG

Applescript to change the all column widths in Numbers

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.