Skip to content

Instantly share code, notes, and snippets.

@guysmoilov
Last active June 18, 2026 19:24
Show Gist options
  • Select an option

  • Save guysmoilov/87fd05fb54d2502d83a632c5968dfb55 to your computer and use it in GitHub Desktop.

Select an option

Save guysmoilov/87fd05fb54d2502d83a632c5968dfb55 to your computer and use it in GitHub Desktop.
Auto-copy OpenAI Codex dictation to clipboard on macOS using Karabiner-Elements

Codex dictation → clipboard on macOS

OpenAI Codex's dictation shortcut (Ctrl-Shift-V) transcribes your voice and writes the result to ~/.codex/transcription-history.jsonl — but doesn't copy it to the clipboard. This setup does.

This means you can use Codex to transcribe text to anywhere in your laptop, not just as prompts to Codex!

How it works

  1. Karabiner-Elements intercepts Ctrl-Shift-V, passes it through to Codex as normal, then on key-up fires a background script via to_after_key_up.
  2. The script snapshots the current line count of the transcription file, then polls every 0.5s for a new entry (up to 30s timeout).
  3. When a new line appears, it extracts the text field, pipes it to pbcopy, and sends a macOS notification with the copied text.

Installation

1. Install the watcher script

mkdir -p ~/.local/bin
# download codex-transcription-copy from this gist to ~/.local/bin/codex-transcription-copy
chmod +x ~/.local/bin/codex-transcription-copy

2. Install the Karabiner rule

mkdir -p ~/.config/karabiner/assets/complex_modifications
# download codex_transcription_copy.json from this gist to that directory

Then in Karabiner-Elements → Complex Modifications → Add rule, enable "Codex: copy transcription on Ctrl-Shift-V release".

Requirements

Debugging

Karabiner logs script output to /tmp/karabiner-codex-copy.log.

#!/bin/zsh
set -euo pipefail
TRANSCRIPT_FILE="$HOME/.codex/transcription-history.jsonl"
TIMEOUT=30
INTERVAL=0.5
if [[ ! -f "$TRANSCRIPT_FILE" ]]; then
osascript -e 'display notification "Transcription file not found" with title "Codex Copy" subtitle "Error"'
exit 1
fi
initial_lines=$(wc -l < "$TRANSCRIPT_FILE")
elapsed=0
while (( elapsed < TIMEOUT )); do
sleep "$INTERVAL"
elapsed=$(( elapsed + INTERVAL ))
current_lines=$(wc -l < "$TRANSCRIPT_FILE")
if (( current_lines > initial_lines )); then
text=$(tail -1 "$TRANSCRIPT_FILE" | /usr/bin/python3 -c "import sys,json; print(json.load(sys.stdin).get('text',''))")
if [[ -n "$text" ]]; then
printf '%s' "$text" | pbcopy
osascript \
-e 'on run argv' \
-e 'display notification (item 1 of argv) with title "Codex Copy" subtitle "Copied to clipboard"' \
-e 'end run' \
-- "$text"
fi
exit 0
fi
done
osascript -e 'display notification "No new transcription detected (timeout)" with title "Codex Copy"'
exit 1
{
"title": "Codex: copy transcription on Ctrl-Shift-V release",
"rules": [
{
"description": "Pass through Ctrl-Shift-V and on key-up start watching for new transcription",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "v",
"modifiers": {
"mandatory": ["control", "shift"],
"optional": ["any"]
}
},
"to": [
{
"key_code": "v",
"modifiers": ["left_control", "left_shift"]
}
],
"to_after_key_up": [
{
"shell_command": "nohup /bin/zsh -lc '$HOME/.local/bin/codex-transcription-copy' >/tmp/karabiner-codex-copy.log 2>&1 &"
}
]
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment