pyosascript
pyosascript is a type-safe, robust Python library and CLI for macOS AppleScript and JXA (JavaScript for Automation).
Stop writing brittle raw shell strings, fighting quotes, or debugging exit codes manually.
Features
- Bidirectional Variable Injection: Safely pass Python strings, integers, floats, and booleans into AppleScript and JXA without string-concatenation quoting vulnerabilities.
- Structured Results: Returns typed
ExecutionResultwith.output,.returncode,.stderr, and.as_list(). - First-Class Error Handling: Raises descriptive
AppleScriptErrorwith stderr and return code diagnostics. - AppleScript & JXA: Native support for both AppleScript and JavaScript for Automation.
- Clean CLI: Fast CLI
osascript-pybuilt with Typer and Rich. - Zero Heavy Dependencies: Lightweight and fast startup.
Installation
pip install pyosascript
Or with Homebrew (via tap):
brew install ml-lubich/tap/pyosascript
Python API Usage
Simple Evaluation
from pyosascript import run_applescript, run_jxa
# AppleScript
res = run_applescript('return 2 + 2')
print(res.output) # "4"
# JXA (JavaScript for Automation)
res_js = run_jxa('(() => { return "Hello from JXA"; })()')
print(res_js.output) # "Hello from JXA"
Safe Variable Passing
from pyosascript import run_applescript
res = run_applescript(
'return "Hello, " & username & "!"',
variables={"username": "Misha"}
)
print(res.output) # "Hello, Misha!"
App Automation (tell)
from pyosascript import tell
# Tell Finder to get frontmost window name
res = tell("Finder", "get name of front window")
print(res.output)
Parsing Lists
from pyosascript import run_applescript
res = run_applescript('return {"apple", "banana", "cherry"}')
print(res.as_list()) # ['apple', 'banana', 'cherry']
CLI Usage
# Evaluate inline AppleScript
osascript-py eval "return 42"
# Evaluate inline JXA
osascript-py eval -l JavaScript "(() => 100 * 2)()"
# Tell application
osascript-py tell Finder "get name of startup disk"
# Output execution JSON
osascript-py eval "return current date" -j
License
MIT © ml-lubich
Metadata
Release files for pyosascript 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pyosascript-0.1.0.tar.gz | 6.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyosascript-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.8 kB
Release files / pyosascript-0.1.0.tar.gz
| Download URL | pyosascript-0.1.0.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4684f4a44392f06a43b9cc1f080a152ef0bb0d81cbdafa5db31c79ee391cacae
|
|
BLAKE2b-256 checksum How to use checksums |
8f54c08f7228d8ec50303147ec987c3580c04661da379e0f47729b5329f3b26b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / pyosascript-0.1.0-py3-none-any.whl
| Download URL | pyosascript-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
395d1efe73a487157837e72b986b884eb6873f574d78f5712e340f09ca2be05a
|
|
BLAKE2b-256 checksum How to use checksums |
3f3e28ad40bf79e9aebdf05c6cd7fbc188384fa2434e5e92a629b7847373f8ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Security for pyosascript 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.