macOS native utilities for Python
Project description
mm-pymac
macOS native utilities for Python.
Installation
uv add mm-pymac
Usage
Tray / Status Bar
from mm_pymac import TrayApp, MenuItem, MenuSeparator
app = TrayApp(title="My App")
app.set_menu([
MenuItem("Status: running", enabled=False),
MenuSeparator(),
MenuItem("Quit", callback=lambda _: app.quit()),
])
app.start_timer(1.0, lambda: print("tick"))
app.run()
Alerts
from mm_pymac import show_alert
result = show_alert(
"Your task is complete.",
title="Done",
buttons=("Cancel", "OK"),
default_button="OK",
)
if result == "OK":
print("User confirmed")
Lock Screen
from mm_pymac import is_screen_locked
locked = is_screen_locked()
if locked is None:
print("Cannot determine lock state")
elif locked:
print("Screen is locked")
else:
print("Screen is unlocked")
Event subscription
Subscribe to lock/unlock events from a TrayApp. Requires a running NSRunLoop — TrayApp.run() provides it:
from mm_pymac import TrayApp, on_screen_locked, on_screen_unlocked
app = TrayApp(title="My App")
on_screen_locked(lambda: print("Screen locked"))
on_screen_unlocked(lambda: print("Screen unlocked"))
app.run()
Polling watcher (no NSRunLoop required)
Use watch_screen_lock() for scripts with their own main loop:
from mm_pymac import watch_screen_lock
stop = watch_screen_lock(
on_lock=lambda: print("Screen locked"),
on_unlock=lambda: print("Screen unlocked"),
)
# Your own main loop
while True:
do_work()
Clipboard
from mm_pymac import set_clipboard, get_clipboard, clear_clipboard
# Copy text
set_clipboard("Hello, world!")
# Read text (returns None if clipboard has no text)
text = get_clipboard()
# Clear clipboard
clear_clipboard()
# Clear only if clipboard still contains the expected value
clear_clipboard(expected="Hello, world!")
Examples
See the examples/ folder for runnable scripts:
lock_events_cli.py— CLI doing periodic work while lock/unlock events fire in the backgroundlock_events_tray.py— TrayApp showing screen lock state in the menu bar
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mm_pymac-0.0.3.tar.gz
(36.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mm_pymac-0.0.3.tar.gz.
File metadata
- Download URL: mm_pymac-0.0.3.tar.gz
- Upload date:
- Size: 36.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ad740cc9a32c7f1bc2c63be6c2e95c22c1a63ca760e39a4ad578e49da98825d
|
|
| MD5 |
f0ff9c79f4cb8d406fe6cbde729fea46
|
|
| BLAKE2b-256 |
591daa1427655d774110cb34f9fd34bc30f48539ce1fe90242894e149dced3ff
|
File details
Details for the file mm_pymac-0.0.3-py3-none-any.whl.
File metadata
- Download URL: mm_pymac-0.0.3-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fce4e6ac370e931a68cb742a492a44f4071fdccb855613079c74ba03852f0245
|
|
| MD5 |
bee3f1b5e7d8a166aef07b99f5125e8f
|
|
| BLAKE2b-256 |
1790cafbb14548ddc4cd974f68c628d6d53b99e79ee9d606247b3f07e6bb34ce
|