How can AppleScript change the name of a Numbers Table?

I have a folder of summary spreadsheets in which I place summaries of individual files to get totals for the business as a whole. I run this monthly, and have twelve files in the folder, appropriately named "August 2014", "January 2015", etc.


Within each spreadsheet is a table listing the clients individually. I have named the table with the date as part of the title, so the first table is "August 2014 Clients". This is so that when I print the report for distribution, the date is prominently at the top within the title.


My AppleScript takes the August 2014.numbers file, repopulates it with August 2015 data, and renames the file "August 2015.numbers" no problem. But I'd like to have the script automatically rename the table within the spreadsheet so it also reflects the change in year. How do I go about this?

MacBook Pro, OS X Yosemite (10.10.5)

Posted on Sep 15, 2015 4:04 PM

Reply
3 replies

Sep 15, 2015 10:57 PM in response to vjdjr

Without a concrete example, it's hard to be exact, but in Numbers, a table has a name property, so you should be able to do something like:


tell application "Numbers"

set name of table 1 of active sheet of document 1 to "foo"

end tell

You may need to adjust this for the table in question (is it table #1? #2?, etc.) and it's not clear how you're determining what the table name should be - how do you know this is August 2015, vs. July, or 2016?

Sep 15, 2015 11:06 PM in response to vjdjr

Hi,


You can use a script like this :

----------------------------------

tell application "Numbers"

repeat with thisSheet in sheets of document 1

repeat with thisTable in tables of thisSheet

set thisName to name of thisTable -- August 2014 Clients

set newName to my incrementYear(thisName)

set name of thisTable to newName -- August 2015 Clients

end repeat

end repeat

end tell


on incrementYear(t) -- the year is the second word in the table's name

set y to (word 2 of t)

set {tid, text item delimiters} to {text item delimiters, y}

set t to text items of t

set text item delimiters to (y + 1) as text -- increment the year

set t to t as string

set text item delimiters to tid

return t-- the new name

end incrementYear

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.

How can AppleScript change the name of a Numbers Table?

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