CloudSharedData PRO
The CloudSharedData class lets your script read and write an iCloud-backed shared data store and collaborate on it with other users — for example a baby-growth log that the whole family maintains together through the same script.
Data is stored in CloudKit (the owner's private iCloud database) and synced across participants. It requires the user to be signed in to iCloud and a Pro subscription, and the script must declare the cloudSharedData permission.
Who creates a store
A store is identified by a UUID. Scripts are pure consumers — they cannot create or list stores. Instead:
- Create a store in Settings → iCloud Shared Data (or ask the assistant to create one). You get a store UUID.
- Paste that UUID into your script:
new CloudSharedData(uuid). - To collaborate, share the store (from the management page or via
share()/presentShareSheet()below) and have others accept. Once accepted, they paste the same UUID into the same script.
Isolation works by consent, not structure:
- Per script/skill — the first time a given script or skill touches a store, the user is asked to grant access for that script + store. Denying makes all calls for that store fail. Grants can be revoked in Settings → iCloud Shared Data.
- Across users — handled by CloudKit and Apple ID. A user can only access a store that was explicitly shared with them and that they accepted.
Creating an instance
Directory semantics (entries)
Use key/value entries when multiple people append or edit independent records — concurrent appends never conflict.
Attach a binary blob to an entry:
Same key written again overwrites it (last write wins). Editing the same entry concurrently resolves last-writer-wins; appending or removing different keys never conflicts.
Single-file semantics
When the whole store is one document, use the file APIs (independent of entries):
Concurrent writes to the file are last-writer-wins.
Sharing
In the native sheet the user can choose between "only invited people" and "anyone with the link", and read-only vs read-write.
Staying in sync
Methods
Notes
- Requires iCloud sign-in and a Pro subscription; declare the
cloudSharedDatapermission in the script. - Scripts cannot create or list stores — do that in Tools → iCloud Shared Data, or ask the assistant. Scripts consume a store by its UUID.
- Joining a shared store: when someone shares a store with you, tap their share link to open Scripting. It shows the store and an Accept button; after accepting, the store appears in Tools → iCloud Shared Data, where you can copy its ID and paste it into a script.
- The data API (read/write/share-link) works in the app and extensions; the native invite sheet only where a presentation context exists (app, Share / Translation UI extensions).
- Always call the function returned by
onChangewhen you are done observing.
