Where are Templates Stored in Numbers Version 6.0?

Apple has recently released Numbers for Mac version 6.0. One of its new features is that templates are now (finally) synced across devices using iCloud. One of the side effects of this seems to be that the templates are now no longer stored in the same directory that they once were. This is causing some issues for me as a central part of a few of my workflows is creating iWork documents from templates by first checking to see if a template with a particular name exists and, if it doesn’t, duplicating the template from somewhere else (e.g. my applet’s resources bundle) to the directory where the user templates are stored for that particular iWork app.

In recent versions prior to version 6.0 Numbers templates were stored in ~/Library/Containers/com.apple.iWork.Numbers/Data/Library/Application Support/User Templates/

This directory still seems to exist in version 6.0, at least it does if you had templates stored there, but it no longer seems to be where Numbers is looking for templates. Templates that I add to that directory don’t show up in the Numbers template chooser or when querying Numbers with AppleScript.

Does anyone know where they have gone?

If I understand well they are in database files reachable thru:

set p2Lib to (path to library folder from user domain) as text

set db4Numbers to p2Lib & "Containers:com.apple.iWork.Numbers:Data:Library:Application Support:com.apple.iWork.CloudKitStorage:com.apple.iWork.TSKCloudKitPrivateZone.db"
set db4Keynote to p2Lib & "Containers:com.apple.iWork.Keynote:Data:Library:Application Support:com.apple.iWork.CloudKitStorage:com.apple.iWork.TSKCloudKitPrivateZone.db"
set db4Pages to p2Lib & "Containers:com.apple.iWork.Pages:Data:Library:Application Support:com.apple.iWork.CloudKitStorage:com.apple.iWork.TSKCloudKitPrivateZone.db"

The id of user templates which were something like “Users/E086EBAF-10C4-4CBD-ACF2-1B3E79DEF21A”, “Users/6910A781-EA7E-492D-961B-F2167D38FE5B”
are now spelled “CloudKit/E086EBAF-10C4-4CBD-ACF2-1B3E79DEF21A”, “CloudKit/6910A781-EA7E-492D-961B-F2167D38FE5B”.

We may get their names with

tell application "Numbers"
	set BuiltinTemplates4Numbers to name of every template whose id does not start with "CloudKit/"
	set UsersTemplates4Numbers to name of every template whose id starts with "CloudKit/"
end tell

I received the info some days ago from an user which got it from Sal Soghoian.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 9 avril 2019 21:47:16

Thanks so much for this, Yvan!

I’ve played around but can’t quite seem to get much success.

The path you provided is, as you said, a database, not a directory, so I can’t add template files to it. At least I don’t know how to do so. In the same directory as the database file is a directory called Data/. I tried adding the templates to that directory and then quitting and relaunching Numbers but the templates added to that directory don’t show up in the template chooser.

As the prefixes of the ids are CloudKit/ as you said,I tried adding templates to ~/Library/Containers/com.apple.iWork.Numbers/Data/cloudKit/ to see if that was the magic directory but templates added to that folder don’t show up in the template chooser either.

I wonder if I haven’t found the right directory yet or if iWork apps simply will no longer recognise templates that are added to the directory if you haven’t added them through the GUI.

Or perhaps an entry needs to be added to that database file somehow.

Any ideas?

Since several versions, we aren’t allowed to use the brave old fashioned scheme to add a template.
Now - why make it simple when it can be complicated - we must create a document then select the menu item [Save as a template] which gives a three buttons dialog offering the ability to add the template to the database.

If we want to remove a custom template we must enter the menu [new document] with option depressed then, select the custom template to remove while pressing the control key. Then we are offered a menu with two items : [Rename, Delete]. I’m not sure of the exact wording because I work with the french version.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 14 avril 2019 16:55:12

I was still able to use the good old method in the version immediately prior to version 6.0. I just copied the template to ~/Library/Containers/com.apple.iwork.Numbers/Data/Library/Application Support/user Templates/, relaunched Numbers and the template would be there.

It would be a shame if it really wasn’t possible to do it that way anymore. The GUI method, which I used to use before I discovered that you could simply copy the files into the right directory, is much less elegant for users of the script who may be put off by seeing menus open and close and dialogues come and go with no input from them. But if that’s what it takes…

One thing I’d add is that another way to add a template the GUI way is to tell the relevant app to open the template (which will bring up a dialogue prompting the user to add it to the template chooser) and then do key code 36 which will activate the default button which is to ad it to the template chooser (although the app might have to be frontmost for that to work).

Anyway, thanks for your help and the discussion, Yvan! And if anyone discovers another way of doing this I’d love to hear.