mirror of
https://github.com/yusufipk/dikte.git
synced 2026-09-11 10:56:10 +00:00
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:
+73
-19
@@ -5,13 +5,34 @@
|
||||
set -euo pipefail
|
||||
|
||||
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PY="$(command -v python3 || true)"
|
||||
USER_NAME="$(id -un)"
|
||||
BIN_DIR="$HOME/.local/bin"
|
||||
APP_DIR="$HOME/.local/share/applications"
|
||||
AUTOSTART_DIR="$HOME/.config/autostart"
|
||||
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/dikte"
|
||||
DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/dikte"
|
||||
|
||||
# What an installation is made of differs by platform, but what --purge deletes
|
||||
# and what it asks before deleting it does not, which is why this is one script
|
||||
# with two sets of paths rather than two scripts.
|
||||
if [[ "$(uname -s)" == "Darwin" ]]; then
|
||||
MACOS=1
|
||||
MAC_APP="$HOME/Applications/Dikte.app"
|
||||
AGENT_ID="io.github.yusufipk.dikte"
|
||||
AGENT="$HOME/Library/LaunchAgents/$AGENT_ID.plist"
|
||||
CONFIG_DIR="$HOME/Library/Application Support/Dikte"
|
||||
DATA_DIR="$CONFIG_DIR"
|
||||
# The interpreter this installation was put on, which is not necessarily the
|
||||
# python3 on PATH: Apple's is 3.9 and cannot run Dikte. The wrapper written
|
||||
# by install-mac.sh names it, so it is read back out of there.
|
||||
# `|| true` because there may be no wrapper to read: pipefail would otherwise
|
||||
# make a missing file the end of the script rather than a question answered no.
|
||||
PY="$(sed -n 's/^exec "\([^"]*\)".*/\1/p' "$BIN_DIR/dikte" 2>/dev/null | head -1 || true)"
|
||||
[[ -x "$PY" ]] || PY="$(command -v python3 || true)"
|
||||
else
|
||||
MACOS=0
|
||||
APP_DIR="$HOME/.local/share/applications"
|
||||
AUTOSTART_DIR="$HOME/.config/autostart"
|
||||
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/dikte"
|
||||
DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/dikte"
|
||||
PY="$(command -v python3 || true)"
|
||||
fi
|
||||
|
||||
PURGE=0
|
||||
ASSUME_YES=0
|
||||
@@ -63,8 +84,12 @@ echo "──────────────────"
|
||||
|
||||
# 1. Global shortcuts ------------------------------------------------------
|
||||
# Handed to Dikte while it can still run, because it is the half that knows
|
||||
# whether they went into KDE's kglobalshortcutsrc or GNOME's gsettings.
|
||||
if [[ -n "$PY" ]] && python3 -c 'import PyQt6.QtWidgets' 2>/dev/null; then
|
||||
# whether they went into KDE's kglobalshortcutsrc or GNOME's gsettings. macOS
|
||||
# keeps no registry: the combinations are held by the running process and are
|
||||
# gone the moment it stops, so there is nothing here to take back.
|
||||
if ((MACOS)); then
|
||||
say "Nothing to unregister: macOS shortcuts live only while Dikte runs."
|
||||
elif [[ -n "$PY" ]] && "$PY" -c 'import PyQt6.QtWidgets' 2>/dev/null; then
|
||||
for which in toggle cancel ask meeting; do
|
||||
"$PY" "$DIR/dikte.py" shortcut remove "$which" >/dev/null 2>&1 || true
|
||||
done
|
||||
@@ -89,25 +114,49 @@ if pgrep -u "$USER_NAME" -f 'dikte\.py' >/dev/null 2>&1; then
|
||||
fi
|
||||
|
||||
# 3. Launchers -------------------------------------------------------------
|
||||
# Only our own symlink goes: a file of the same name that somebody else put
|
||||
# there is not ours to delete.
|
||||
# Only what this installer wrote goes: a file of the same name that somebody
|
||||
# else put there is not ours to delete. On Linux ours is a symlink; on macOS it
|
||||
# is a generated wrapper, which says so in its second line.
|
||||
if [[ -L "$BIN_DIR/dikte" ]]; then
|
||||
remove "$BIN_DIR/dikte"
|
||||
elif ((MACOS)) && grep -q 'Written by install-mac.sh' "$BIN_DIR/dikte" 2>/dev/null; then
|
||||
remove "$BIN_DIR/dikte"
|
||||
elif [[ -e "$BIN_DIR/dikte" ]]; then
|
||||
warn "$BIN_DIR/dikte is not our symlink, leaving it alone"
|
||||
warn "$BIN_DIR/dikte is not ours, leaving it alone"
|
||||
else
|
||||
gone "Was not there: $BIN_DIR/dikte"
|
||||
fi
|
||||
remove "$APP_DIR/dikte.desktop"
|
||||
remove "$AUTOSTART_DIR/dikte.desktop"
|
||||
# Removing the shortcut takes its desktop file with it, but an install from
|
||||
# before this script existed may have left one behind on a desktop that never
|
||||
# used them.
|
||||
for id in dikte-toggle dikte-cancel dikte-ask dikte-meeting; do
|
||||
if [[ -e "$APP_DIR/$id.desktop" ]]; then
|
||||
remove "$APP_DIR/$id.desktop"
|
||||
|
||||
if ((MACOS)); then
|
||||
# The login item first: bootout while the plist is still there, because
|
||||
# launchctl is told which job by the file as much as by the label.
|
||||
if [[ -e "$AGENT" ]]; then
|
||||
launchctl bootout "gui/$(id -u)/$AGENT_ID" >/dev/null 2>&1 || true
|
||||
fi
|
||||
done
|
||||
remove "$AGENT"
|
||||
if [[ -d "$MAC_APP" ]]; then
|
||||
rm -rf "$MAC_APP"
|
||||
ok "Removed $MAC_APP"
|
||||
else
|
||||
gone "Was not there: $MAC_APP"
|
||||
fi
|
||||
# macOS keeps the permissions filed against the bundle that asked for them,
|
||||
# and deleting the bundle does not withdraw them.
|
||||
say "Microphone and Accessibility are still granted to Dikte; take them back"
|
||||
say "under System Settings → Privacy & Security if you want them gone."
|
||||
fi
|
||||
if ((!MACOS)); then
|
||||
remove "$APP_DIR/dikte.desktop"
|
||||
remove "$AUTOSTART_DIR/dikte.desktop"
|
||||
# Removing the shortcut takes its desktop file with it, but an install from
|
||||
# before this script existed may have left one behind on a desktop that never
|
||||
# used them.
|
||||
for id in dikte-toggle dikte-cancel dikte-ask dikte-meeting; do
|
||||
if [[ -e "$APP_DIR/$id.desktop" ]]; then
|
||||
remove "$APP_DIR/$id.desktop"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# 4. Settings and dictations -----------------------------------------------
|
||||
echo
|
||||
@@ -142,6 +191,11 @@ fi
|
||||
if ((PURGE)); then
|
||||
rm -rf "$CONFIG_DIR" "$DATA_DIR"
|
||||
ok "Settings and dictations deleted"
|
||||
elif [[ "$CONFIG_DIR" == "$DATA_DIR" ]]; then
|
||||
# macOS keeps both in the one directory a Mac user's backup already knows
|
||||
# about, so naming it twice would only look like two things were kept.
|
||||
say "Settings and dictations kept: $CONFIG_DIR"
|
||||
say "Delete them too with: ./uninstall.sh --purge"
|
||||
else
|
||||
say "Settings kept: $CONFIG_DIR"
|
||||
say "Dictations kept: $DATA_DIR"
|
||||
|
||||
Reference in New Issue
Block a user