Skip to main content

macscript

Script macOS applications from Python, using appscript. Start with Microsoft Word; use the vocabulary helpers to explore any scriptable app.

Requires macOS. Word automation also requires Microsoft Word. macOS may ask you to allow Automation access; dialog controls use Accessibility access, and screenshots need Screen Recording access.

Word

from macscript.word import new_doc, set_text, doc_text, save_docx, close_doc

doc = new_doc()
set_text(doc, 'Hello from Python!')
print(doc_text(doc))
doc = save_docx(doc, 'hello.docx')
close_doc(doc)

open_doc(path) opens an existing document. save_docx returns a fresh document reference because saving under a new name makes the old reference stale. save_pdf(doc, path) exports a PDF. close_doc discards unsaved changes unless passed save=True. Body text returned by doc_text uses LF line endings.

word() returns the appscript application proxy for commands not wrapped here. Document operations accept a timeout in seconds; the default is 15.

Screenshots and dialogs

  • win_pic(path) captures Word's front document window on the current Space. An occluded window can still be captured.
  • win_id() returns its window ID; win2png(window_id, path) captures a window by ID.
  • dlg_read() returns the front dialog's button names and message, or None.
  • dlg_click(label) clicks a named button.
  • dismiss_dlgs() dismisses dialogs and returns their messages. It chooses OK, then No, then the first available button; use it only when that behavior is appropriate.

Dialog queries default to a three-second timeout. They use System Events so they can work while Word's own event queue is blocked by a modal dialog.

Discover scripting commands

Word's scripting dictionary is bundled, so its documentation can be searched without launching Word:

from macscript.word import sd, sdfind

print(sd('document'))
print(sd('save_as'))
sdfind('bookmark')

sd shows a command, class, or enumeration with types and descriptions. Underscores and spaces both work in names. sdfind searches names and descriptions with a case-insensitive regex and returns (kind, name, description) rows.

The generic helpers work with other appscript apps too:

from appscript import app
from macscript.asvocab import vocab, props, sd, sdfind

finder = app('Finder')
vocab(finder, 'selection|window')
props(finder, 'name')
sd('application', path='Finder.sdef')

vocab searches an app's live terminology. props reads a reference's properties as a dictionary of names and truncated representations, with optional regex filtering. Generic sd and sdfind require an explicit .sdef path; only the Word module supplies a Word default.

Development

Install the checkout and its development dependencies:

pip install -e '.[dev]'
python -m pytest -q

The default tests exercise scripting documentation without launching apps. There is no dependency on mdhtml2docx or oxml; document validation and converter acceptance checks belong to their callers. App-specific behavior lives in app modules, with reusable scripting exploration in asvocab.

Metadata

Release files for macscript 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for macscript 0.1.0
File Size Uploaded Provenance Actions
macscript-0.1.0.tar.gz 143.2 kB Without provenance Details for macscript-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for macscript 0.1.0
File Interpreter ABI Platform Actions
macscript-0.1.0-py3-none-any.whl Python 3 none any Details for macscript-0.1.0-py3-none-any.whl

Total release size: 289.3 kB

Release files / macscript-0.1.0.tar.gz

Download URL macscript-0.1.0.tar.gz
Size 143.2 kB
Tags Source
SHA-256 checksum
How to use checksums
752feebfeb21df04b1251b8afd19da48b2abcfc74620d07b1ee6bd8af1028231
BLAKE2b-256 checksum
How to use checksums
c85d60bd3efbb6c9ac5bf28dc07f3114d27a28596b10f3616e084203ff2a9d49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / macscript-0.1.0-py3-none-any.whl

Download URL macscript-0.1.0-py3-none-any.whl
Size 146.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c02816dba13a11fe895887d50f4c1d8174a37fe2d4a5e7a588fcb68d852e6c6c
BLAKE2b-256 checksum
How to use checksums
6fef67c8bb09320d1408376444f4863a009caaddf9efc7ea1a0c9e1e3cd28a28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Security for macscript 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page