Can I change a Numbers spreadsheet background color via AS?

My macro will duplicate sheets and change some cell values based on some KM variables and I have the last part done.

I am using the script provided here to duplicate a sheet:

but my original sheet has a dark background color and when I use the script shared above, the background is white. Can I change the background color via AS?
I know how to change it manually by going to Format > Sheet > Background, but I would like to do it all with the same script, if possible.

You can, though this bit of script will need some customization to work for your setup, as it's quite generic:

tell application "Numbers"
	activate
	tell front document
		tell sheet "Sheet 1"
			tell front table
				set targetRange to range "A1:B2" -- set to desired range
				set backgroundColor to {65535, 0, 0} -- Red, but set to what you want
				set background color of targetRange to backgroundColor
			end tell
		end tell
	end tell
end tell

AppleScript is not my strong suit; I cobbled this together after looking at the AppleScript Dictionary for Numbers.

-rob.

1 Like

I saw that solution online as well, but what I was looking for (maybe my post wasn't that clear, sorry) was to change the sheet's background, not the table's.

When you unselect all content in a sheet, under Format on the right sidebar you will see that you can change the background color for the sheet.

Maybe that's not possible and I decided to approach it a different way by duplicating the original sheet manually and then just copying the original table and pasting it on the different duplicated sheets. Simpler and less script involved

The dictionary only talks about being able to set a range's background, not the whole sheet, sorry. Sounds like you wound up with a better solution anyway :).

-rob.

1 Like

Yes, my "solution" seems a bit less complicated.
I could use the Found Image action and do it that way, but for this particular case, it was easier to do it the way I did it. :slight_smile:

Thanks for your time and help. Always extremely helpful!