macOS clipboard image AppleScript never compiles, osascript path is dead code
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 19.9k
- Forks
- 2.3k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 30
Description
Summary
The macOS branch of clipboard_image() in crates/jcode-tui/src/tui/app/helpers.rs has never worked. The AppleScript fails to compile, so the whole osascript path is dead code and every image paste on macOS silently falls through to the arboard fallback.
Low user-visible impact, because arboard catches it. Filing it because the branch is a trap for whoever edits it next, and the intended higher-fidelity path is unreachable.
Environment
- macOS 15, aarch64
- jcode v0.84.0 (57d5878)
Reproduction
Straight from the shipped binary, no build required:
$ strings -a ~/.local/bin/jcode | grep representationUsingType
set pngData to bitmapRep's representationUsingType:(current application's NSBitmapImageFileTypePNG) properties:(missing value)
$ osascript -l AppleScript -e '<that same script>'
595:605: syntax error: Expected end of line, etc. but found plural class name. (-2741)
Expected: the script writes a PNG and returns ok or none.
Actual: it never compiles, so clipboard_image() always reaches the arboard fallback on macOS.
Root cause
Three defects in one string literal:
propertiesis a plural class name in AppleScript's grammar. An unquotedproperties:label in an ObjC-style message send aborts compilation with-2741before any statement runs. It has to be escaped as|properties|:.representationUsingType:properties:rejectsmissing valuefor that argument and needs a real dictionary.\"escapes inside a Rust raw string.r#"use framework \"AppKit\""#passes literal backslashes toosascript -e, a syntax error on line 1 regardless of the rest.
Verified fix
set pngType to current application's NSBitmapImageFileTypePNG
set emptyProps to current application's NSDictionary's dictionary()
set pngData to bitmapRep's representationUsingType:pngType |properties|:emptyProps
Both branches checked by hand:
$ osascript -e 'set the clipboard to "halo"' && osascript -l AppleScript -e '<new script>'
none
$ osascript -e 'set the clipboard to (read (POSIX file "~/Pictures/Avatar.png") as «class PNGf»)'
$ osascript -l AppleScript -e '<new script>'
ok
$ file /tmp/jcode_clip_verify.png
PNG image data, 1254 x 1254, 8-bit/color RGB, non-interlaced
Reference branch
I have a branch with the fix plus two regression tests, but I cannot open a PR against this repo (CreatePullRequest returns a permissions error for my account), so linking it here instead:
https://github.com/aphelion31/jcode/tree/fix/macos-clipboard-image-applescript
Diff (2 files, +105/-17): https://github.com/1jehuang/jcode/compare/master...aphelion31:jcode:fix/macos-clipboard-image-applescript
Contents:
- Script body extracted into
macos_clipboard_png_script()so it is testable without a clipboard fixture. - Nil guards on
imgList/tiffData/bitmapRep/pngData, which would have thrown at runtime had the script ever compiled. macos_clipboard_script_escapes_the_properties_labelasserting source shape.macos_clipboard_script_compiles_and_runs_under_osascriptactually invokingosascript, so a rewrite that changes the string shape is still covered. An empty clipboard is a valid fixture: it exercises the full parse plus theelsebranch.
Both tests fail against the old script and pass against the new one, confirmed by reverting the fix in place:
# old script
test result: FAILED. 0 passed; 2 failed
AppleScript failed to compile: 798:808: syntax error: Expected end of line,
etc. but found plural class name. (-2741)
# fixed
test result: ok. 2 passed; 0 failed
cargo clippy --profile selfdev -p jcode-tui is clean on the touched file.
Edge cases and tradeoffs
- Fixing this makes the
osascriptpath take priority overarboardon macOS, as originally intended. It writes native PNG bytes rather than re-encoding decoded RGBA, so it is a fidelity improvement, but also a behavior change for anyone whose output currently comes fromarboard. - The temp file is still a fixed
jcode_clipboard.png, unchanged. Two concurrent instances pasting at once could race. Out of scope, noting it. - The compile test shells out to
osascript. macOS-gated and sub-second, but not hermetic. Reasonable to drop it and keep only the string-shape assertion. - Unrelated but easy to conflate: terminals that intercept
Cmd+V(VS Code's integrated terminal) hand jcode text-only paste and never reach this code.Ctrl+V/Alt+Vwork fine there. Different failure mode, terminal-side.
Per CONTRIBUTING.md, treating the branch as a reference and reproduction rather than something to merge as-is.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in crates/jcode-tui/src/tui/app/helpers.rs at the macOS branch of clipboard_image() and inspect the AppleScript string and its osascript invocation. Use the named macos_clipboard_script_escapes_the_properties_label and macos_clipboard_script_compiles_and_runs_under_osascript tests as guidance, then run cargo clippy --profile selfdev -p jcode-tui; done means the script compiles, returns the expected result, and the regression tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- macos, rust
- Domain
- cli, desktop
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100