Using Script Editor

Back in May 2020 S Gill kindly provided a solution to my problem of how to change the month on multiple sheets in Numbers; I now need to change the year!!


SG, would you mind telling me how please? ...or anyone else perhaps.


Most grateful. PSG


SG wrote "......... it appears that you have a month abbreviation in the name of the first table in each sheet, not in a cell.


If so, you can use a simple script like the one below to update the month abbreviation on all your sheets with one click or a menu choice.


To install:

  1. Copy-paste script below into Script Editor (in Applications > Utilities).
  2. Make sure Script Editor and Numbers are listed and checked at System Preferences > Security & Privacy > Privacy > Accessibility


To run:

  1. With your Numbers document open, click the <run> button in Script Editor.
  2. Or, since you will be using this each month, you can make it a menu choice by installing it in the Script Menu.


Installation is quick. You don't need to know AppleScript to use this. It simply becomes an additional item in the menu.


If, instead, you do have the month abbreviation in the same cell in tables on different sheets that can also be scripted easily. Just post if that is the case.


SG



Posted on Jan 6, 2022 1:48 AM

Reply
Question marked as Top-ranking reply

Posted on Jan 6, 2022 4:19 AM

With the position of the year as the second to last "word" in the name of the table this script should work to update the year in name of the first table on each sheet.


set newYear to choose from list {"2022", "2023", "2024"}
set newYear to newYear as text
tell front document of application "Numbers"
	repeat with s in sheets
		tell s
			set oldName to name of table 1
			set newName to my findRepl(word -2 of oldName, newYear, oldName)
			set name of table 1 to newName
		end tell
	end repeat
end tell

to findRepl(s, r, t)
	set text item delimiters to s
	set newVal to text items of t
	set text item delimiters to r
	return newVal as string
end findRepl



SG

4 replies
Question marked as Top-ranking reply

Jan 6, 2022 4:19 AM in response to PaulSG

With the position of the year as the second to last "word" in the name of the table this script should work to update the year in name of the first table on each sheet.


set newYear to choose from list {"2022", "2023", "2024"}
set newYear to newYear as text
tell front document of application "Numbers"
	repeat with s in sheets
		tell s
			set oldName to name of table 1
			set newName to my findRepl(word -2 of oldName, newYear, oldName)
			set name of table 1 to newName
		end tell
	end repeat
end tell

to findRepl(s, r, t)
	set text item delimiters to s
	set newVal to text items of t
	set text item delimiters to r
	return newVal as string
end findRepl



SG

Jan 6, 2022 3:36 AM in response to PaulSG

PaulSG wrote:

how to change the month on multiple sheets in Numbers; I now need to change the year!!


Where to you have the year? Is it in the name of tables on each sheet or somewhere else? The easiest way to explain might be to just post a screenshot. To do that type shift-command-4, use the cross-hairs to select the desired area on the screen, release, then start a new post here and use the "mountains and moon" icon to insert the screenshot image from the Desktop.


SG

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Using Script Editor

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