Give a Mac an installer, an app bundle and a menu bar icon it can see

The macOS backends were already here: CoreAudio capture through ffmpeg,
pbcopy and CoreGraphics, Carbon hotkeys, the paths under ~/Library. What
was missing was everything that installs them, so install.sh hands over to
install-mac.sh on Darwin rather than growing a branch per line: the XDG
directories, the .desktop files and the shortcut registry mean nothing
there, and an application is a bundle rather than a path. The bundle
carries a copy of the interpreter, because macOS files the microphone and
Accessibility permissions against the process that asks, and a launcher
running Homebrew's python3 would have asked as python3 and shared the
grant with everything else on that interpreter. It is signed ad-hoc so a
reinstall is the same application rather than two more dialogs, and it
says so plainly when a brew upgrade has moved the tree it needs.
uninstall.sh and update.sh follow it.

The tray icon was invisible: QIcon.fromTheme wants a freedesktop icon
theme and hands back a null icon without one, which in a menu bar is the
whole interface gone. trayicon.py draws the three shapes as template
images, so they follow the menu bar into dark mode, and the bundle's icon
comes off the same glyph rather than a binary in the repository. Linux
keeps its own icons; these are used only where the theme has nothing.

paths.py is the fix that was never about a Mac. config.py imports ggml.py,
so ggml.py could not ask it where the data goes; each worked it out for
itself and only one of them knew about macOS. Settings went to ~/Library
while several gigabytes of models went to ~/.local/share, which is not a
place a Mac user looks and not a place uninstall.sh --purge would have
deleted from.

Ctrl+Space is the input-source switch there and Cmd+Space is Spotlight, so
the default is Ctrl+Option+Space, and hotkey.default_combo is the one
place that difference lives. The first paste asks for Accessibility with
kAXTrustedCheckOptionPrompt, which is what creates the row to switch on;
asking the other way opens a pane Dikte is not listed in. `dikte shortcut
status` asks the running instance, since the combination is held by that
process and by nothing else.

Local speech to text is the one piece a Mac builds by hand. whisper.cpp
publishes no macOS binary and Homebrew's is configured with
WHISPER_BUILD_SERVER=OFF, so it installs whisper-cli and not the server
Dikte talks to; program_path already takes a whisper-server off the PATH
or out of Settings, so the answer is the one a Linux distribution gets,
and the README carries the cmake line. CI grows a macOS job on 3.11 and
3.13, the only place the Carbon and CoreGraphics libraries have to be
there to be opened.

Written and tested on macOS 27.0 arm64. Two things are still unverified on
a Mac: the paste end to end, which waits on the Accessibility toggle, and
a meeting recording, which needs a loopback driver.
This commit is contained in:
Can Soykan Yılmaz
2026-08-15 15:56:27 +03:00
committed by GitHub
parent 77b26e76be
commit 44cfb76652
24 changed files with 1116 additions and 102 deletions
+56 -4
View File
@@ -200,6 +200,14 @@ def _macos_api():
tool="CoreGraphics", error=exc)) from exc
services.AXIsProcessTrusted.argtypes = []
services.AXIsProcessTrusted.restype = ctypes.c_bool
services.AXIsProcessTrustedWithOptions.argtypes = [ctypes.c_void_p]
services.AXIsProcessTrustedWithOptions.restype = ctypes.c_bool
core.CFDictionaryCreate.argtypes = [
ctypes.c_void_p, ctypes.POINTER(ctypes.c_void_p),
ctypes.POINTER(ctypes.c_void_p), ctypes.c_long,
ctypes.c_void_p, ctypes.c_void_p,
]
core.CFDictionaryCreate.restype = ctypes.c_void_p
services.CGEventCreateKeyboardEvent.argtypes = [
ctypes.c_void_p, ctypes.c_ushort, ctypes.c_bool,
]
@@ -224,16 +232,60 @@ def _macos_trusted():
_asked_for_permission = False
def _ask_for_permission():
"""Open the one settings pane that grants it, and only the first time.
def _macos_prompt_options(services, core):
"""{kAXTrustedCheckOptionPrompt: true}, as a CFDictionary, or 0.
Every dictation would otherwise reopen it until the box is ticked, which is
a window in the user's face on top of the paste that did not happen.
Built by hand because there is no Objective-C bridge here and this is the
only dictionary Dikte ever makes. Its own function so that a test can hand
back something without a framework to read the constants out of.
"""
keys = (ctypes.c_void_p * 1)(
ctypes.c_void_p.in_dll(services, "kAXTrustedCheckOptionPrompt"))
values = (ctypes.c_void_p * 1)(
ctypes.c_void_p.in_dll(core, "kCFBooleanTrue"))
return core.CFDictionaryCreate(
None, keys, values, 1,
ctypes.byref(ctypes.c_void_p.in_dll(core, "kCFTypeDictionaryKeyCallBacks")),
ctypes.byref(ctypes.c_void_p.in_dll(core, "kCFTypeDictionaryValueCallBacks")),
)
def _macos_put_us_in_the_list():
"""Ask with the prompt, which is what creates the row to switch on.
AXIsProcessTrusted only answers the question, and an application that has
only ever asked it is not in Accessibility at all: the pane opens on a list
Dikte is not in, and the only way through is the + button and a trip to the
Applications folder. Asking with kAXTrustedCheckOptionPrompt puts it there,
and macOS shows its own dialog with the button that opens the pane.
"""
services, core = _macos_api()
options = _macos_prompt_options(services, core)
if not options:
return
try:
services.AXIsProcessTrustedWithOptions(options)
finally:
core.CFRelease(options)
def _ask_for_permission():
"""Get Dikte into the Accessibility list, and only the first time.
Every dictation would otherwise reopen the pane until the box is ticked,
which is a window in the user's face on top of the paste that did not
happen.
"""
global _asked_for_permission
if _asked_for_permission:
return
_asked_for_permission = True
try:
_macos_put_us_in_the_list()
except (PasteError, OSError, ValueError):
# An older macOS, or a framework that would not load: the pane below is
# still worth opening, even if the row has to be added by hand.
pass
try:
subprocess.Popen(
["open", ("x-apple.systempreferences:com.apple.preference.security"