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
+51
View File
@@ -333,6 +333,57 @@ class ConfigCommands(DikteTest):
{"cleanup", "subtitles", "meeting", "agent"})
class ShortcutStatus(DikteTest):
"""Where the answer comes from, which is not one place on every system.
macOS keeps no shortcut registry: a combination is held by the running
process and by nothing else, so a command line that reads its own idea of
"installed" reports every shortcut as missing while all of them work.
"""
def run_cmd(self, func, **values):
with captured() as (out, err):
code = func(Options(**values))
return code, out.getvalue(), err.getvalue()
def status(self, reply):
with mock.patch.object(ipc, "send", return_value=reply) as send:
code, out, _ = self.run_cmd(cli.cmd_shortcut, shortcut="status",
json=True)
return code, json.loads(out), send
def test_what_the_running_instance_holds_is_what_is_reported(self):
code, answer, _ = self.status({
"shortcuts": {"toggle": "Ctrl+Option+Space", "cancel": None,
"ask": None, "meeting": None},
"listener": True,
})
self.assertEqual(code, 0)
self.assertEqual(answer["shortcuts"]["toggle"]["registered"],
"Ctrl+Option+Space")
self.assertIsNone(answer["shortcuts"]["cancel"]["registered"])
self.assertIs(answer["listener"], True)
def test_the_instance_is_the_one_asked(self):
_, _, send = self.status({"shortcuts": {}, "listener": False})
send.assert_called_once_with("status")
def test_nothing_running_falls_back_to_what_this_process_can_read(self):
"""Which on Linux is the registry, and on macOS is nothing, correctly
so, because there the keys really are gone with the process."""
code, answer, _ = self.status(None)
self.assertEqual(code, 0)
for name, spec in hotkey.SHORTCUTS.items():
with self.subTest(name=name):
self.assertEqual(answer["shortcuts"][name]["registered"],
hotkey.shortcut_status(spec.desktop_id))
def test_the_configured_combination_is_reported_either_way(self):
code, answer, _ = self.status(None)
self.assertEqual(answer["shortcuts"]["toggle"]["configured"],
cfg.Config()["shortcut"])
class Providers(DikteTest):
"""The terminal reaches every provider the settings window does."""
-28
View File
@@ -460,34 +460,6 @@ class Defaults(unittest.TestCase):
paste.desktop().shortcuts[0])
class Directories(unittest.TestCase):
"""Where the settings and the recordings are kept, per system."""
def test_linux_keeps_them_apart_and_follows_xdg(self):
with mock.patch.dict(os.environ, {"XDG_CONFIG_HOME": "/c",
"XDG_DATA_HOME": "/d"}):
config_dir, data_dir = cfg._directories("linux")
self.assertEqual(str(config_dir), "/c/dikte")
self.assertEqual(str(data_dir), "/d/dikte")
def test_linux_without_the_variables_set(self):
with mock.patch.dict(os.environ, {}, clear=True):
config_dir, data_dir = cfg._directories("linux")
self.assertTrue(str(config_dir).endswith("/.config/dikte"))
self.assertTrue(str(data_dir).endswith("/.local/share/dikte"))
def test_a_mac_keeps_both_in_application_support(self):
config_dir, data_dir = cfg._directories("darwin")
self.assertEqual(config_dir, data_dir)
self.assertTrue(str(config_dir).endswith("/Library/Application Support/Dikte"))
def test_a_mac_does_not_read_the_xdg_variables(self):
"""A Mac with them set from some other tool still stores in one place."""
with mock.patch.dict(os.environ, {"XDG_CONFIG_HOME": "/c"}):
config_dir, _ = cfg._directories("darwin")
self.assertNotIn("/c", str(config_dir))
if __name__ == "__main__":
unittest.main()
+1 -1
View File
@@ -226,7 +226,7 @@ class InstallProgram(Local):
with fake_urlopen(listing):
with self.assertRaises(ggml.LocalError) as caught:
ggml.install_program(ggml.WHISPER)
self.assertIn("brew install whisper-cpp", str(caught.exception))
self.assertIn("Build whisper-server yourself", str(caught.exception))
def test_a_mac_uses_the_native_llama_archive_instead_of_ubuntu(self):
self.patch_attr(sys, "platform", "darwin")
+10
View File
@@ -78,6 +78,16 @@ class Table(unittest.TestCase):
self.assertEqual([name for name, spec in hotkey.SHORTCUTS.items()
if spec.fallback], ["toggle"])
def test_the_fallback_a_mac_gets_is_not_one_macos_already_holds(self):
"""Ctrl+Space switches the input source there and Cmd+Space is
Spotlight, so the table's own fallback is Linux's and only Linux's."""
with mock.patch.object(hotkey.sys, "platform", "darwin"):
self.assertEqual(hotkey.default_combo("toggle"), "Ctrl+Option+Space")
self.assertEqual(hotkey.default_combo("cancel"), "")
with mock.patch.object(hotkey.sys, "platform", "linux"):
self.assertEqual(hotkey.default_combo("toggle"), "Ctrl+Space")
self.assertEqual(hotkey.default_combo("cancel"), "")
class ModsMatch(unittest.TestCase):
"""The combination has to be exact, or Ctrl+Space fires on Ctrl+Shift+Space."""
+36
View File
@@ -275,11 +275,16 @@ class FakeCoreGraphics:
self.flags = [] # (event, flags)
self.posted = [] # (tap, event)
self.released = []
self.prompted = [] # the options dictionaries asked with
# --- ApplicationServices
def AXIsProcessTrusted(self):
return self.trusted
def AXIsProcessTrustedWithOptions(self, options):
self.prompted.append(options)
return self.trusted
def CGEventCreateKeyboardEvent(self, source, keycode, down):
self.made.append((keycode, down))
if self.makes is not None and len(self.made) > self.makes:
@@ -301,10 +306,16 @@ class MacOS(ClipboardContract, DikteTest):
platform = "darwin"
here = paste.MACOS
# A stand-in for the CFDictionary: the real one is built out of constants
# read from the frameworks, which a fake has none of.
OPTIONS = 4242
def setUp(self):
super().setUp()
self.api = FakeCoreGraphics()
self.patch_attr(paste, "_macos_api", lambda: (self.api, self.api))
self.patch_attr(paste, "_macos_prompt_options",
lambda services, core: self.OPTIONS)
self.patch_attr(paste.time, "sleep", lambda seconds: None)
# It opens the settings pane once per run; each test gets its own run.
self.patch_attr(paste, "_asked_for_permission", False)
@@ -385,6 +396,31 @@ class MacOS(ClipboardContract, DikteTest):
paste.press("cmd+v")
self.assertIn("Accessibility", str(caught.exception))
def test_asking_is_what_puts_dikte_in_the_accessibility_list(self):
"""Opening the pane is not enough on its own.
AXIsProcessTrusted only answers the question; an application that has
never asked with the prompt is not in the list, so the pane opens on a
list Dikte is not in and the only way through is the + button.
"""
self.api.trusted = False
with self.assertRaises(paste.PasteError):
paste.press("cmd+v")
self.assertEqual(self.api.prompted, [self.OPTIONS])
# The dictionary is ours to release, and nothing else made an event.
self.assertIn(self.OPTIONS, self.api.released)
def test_it_asks_once_however_many_dictations_fail(self):
self.api.trusted = False
for _ in range(3):
with self.assertRaises(paste.PasteError):
paste.press("cmd+v")
self.assertEqual(len(self.api.prompted), 1)
def test_a_trusted_process_is_never_prompted(self):
paste.press("cmd+v")
self.assertEqual(self.api.prompted, [])
def test_readiness_is_the_permission_rather_than_a_program(self):
self.assertTrue(paste.paste_ready())
self.api.trusted = False
+62
View File
@@ -0,0 +1,62 @@
"""Where the settings and the data are kept, per system.
Its own file because the answer has to be one answer: config.py and ggml.py
both need it, and when each worked it out for itself only one of them knew
about macOS.
"""
import os
import unittest
from unittest import mock
import config as cfg
import ggml
import paths
class Directories(unittest.TestCase):
def test_linux_keeps_them_apart_and_follows_xdg(self):
with mock.patch.dict(os.environ, {"XDG_CONFIG_HOME": "/c",
"XDG_DATA_HOME": "/d"}):
config_dir, data_dir = paths.directories("linux")
self.assertEqual(str(config_dir), "/c/dikte")
self.assertEqual(str(data_dir), "/d/dikte")
def test_linux_without_the_variables_set(self):
with mock.patch.dict(os.environ, {}, clear=True):
config_dir, data_dir = paths.directories("linux")
self.assertTrue(str(config_dir).endswith("/.config/dikte"))
self.assertTrue(str(data_dir).endswith("/.local/share/dikte"))
def test_a_mac_keeps_both_in_application_support(self):
config_dir, data_dir = paths.directories("darwin")
self.assertEqual(config_dir, data_dir)
self.assertTrue(str(config_dir).endswith("/Library/Application Support/Dikte"))
def test_a_mac_does_not_read_the_xdg_variables(self):
"""A Mac with them set from some other tool still stores in one place."""
with mock.patch.dict(os.environ, {"XDG_CONFIG_HOME": "/c"}):
config_dir, _ = paths.directories("darwin")
self.assertNotIn("/c", str(config_dir))
class OnePlace(unittest.TestCase):
"""The programs and the models go where everything else goes.
ggml.py used to read XDG_DATA_HOME itself, which is right on Linux and
wrong on a Mac: the settings and the dictations went to ~/Library while
several gigabytes of models went to ~/.local/share, where no Mac user looks
and where `uninstall.sh --purge` would never have found them.
"""
def test_the_models_live_under_the_data_directory(self):
self.assertEqual(ggml.DATA_DIR, paths.DATA_DIR)
self.assertEqual(ggml.MODELS_DIR.parent, paths.DATA_DIR)
self.assertEqual(ggml.BIN_DIR.parent, paths.DATA_DIR)
def test_config_and_ggml_cannot_disagree(self):
self.assertEqual(cfg.DATA_DIR, ggml.DATA_DIR)
if __name__ == "__main__":
unittest.main()
+8 -2
View File
@@ -180,13 +180,19 @@ class Settings(DikteTest):
def test_emptying_a_shortcut_turns_it_off_but_not_the_toggle(self):
"""The application is unusable without the toggle, so that one box
falls back. The rest stay empty, which is how they are switched off."""
falls back. The rest stay empty, which is how they are switched off.
Which combination it falls back to is the platform's and is pinned in
test_hotkey; MacSettings runs this too, and there the answer is not
Ctrl+Space.
"""
conf = cfg.Config()
window = self.window(conf)
for box, _status, _missing in window._shortcut_rows.values():
box.setCurrentText("")
window._save()
self.assertEqual(conf["shortcut"], "Ctrl+Space")
self.assertTrue(conf["shortcut"])
self.assertEqual(conf["shortcut"], hotkey.default_combo("toggle"))
self.assertEqual(conf["cancel_shortcut"], "")
self.assertEqual(conf["assistant_shortcut"], "")
self.assertEqual(conf["meeting_shortcut"], "")