Automates Apple Pages using JXA with AppleScript dictionary discovery...
automating-mac-apps patterns.automating-mac-apps for permissions, shell, and UI scripting guidance.automating-mac-apps skill (PyXA Installation section).doc.body.text()) and assignments for writes (e.g., doc.body.text = 'new text').const pages = Application('Pages');
const doc = pages.Document({templateName: 'Blank'});
pages.documents.push(doc);
doc.body.text = "Hello World";
make new document becomes pages.documents.push(pages.Document()).IMPORTANT: Pages does NOT support direct image insertion like Keynote does:
// THIS WORKS IN KEYNOTE:
Keynote.Image({ file: Path("/path/to/image.png"), position: {x: 100, y: 100} });
// THIS DOES NOT WORK IN PAGES!
Pages.Image({ file: Path("/path/to/image.png") }); // β Will fail
Solution: Use ObjC Pasteboard bridging (see pages-advanced.md for details):
ObjC.import('AppKit');
const nsImage = $.NSImage.alloc.initWithContentsOfFile("/path/to/image.png");
const pb = $.NSPasteboard.generalPasteboard;
pb.clearContents;
pb.setDataForType(nsImage.TIFFRepresentation, $.NSPasteboardTypeTIFF);
// Then use System Events to paste (Cmd+V)
Example Script: See automating-pages/scripts/insert_images.js for a complete working example.
Image constructor unlike Keynote. Use ObjC Pasteboard method.doc.save({in: file_path}) with a valid path object.automating-pages/references/pages-basics.md (Core objects and document lifecycle)automating-pages/references/pages-recipes.md (Standard operations)automating-pages/references/pages-export-matrix.md (PDF, Word, ePub formats)automating-pages/references/pages-template-strategy.md (Managing custom templates)automating-pages/references/pages-advanced.md (Complex integrations)automating-pages/references/pages-ui-scripting.md (Fallbacks)automating-pages/references/pages-dictionary.md (AppleScript to JXA mapping)automating-pages/references/pages-pyxa.mdautomating-pages/scripts/insert_images.js (ObjC Pasteboard method for inserting images)