Skip to content

fix(clipboard): copy macOS file references without Finder automation - #156

Open
gregpriday wants to merge 1 commit into
developfrom
bugfix/macos-file-reference-without-finder
Open

gregpriday wants to merge 1 commit into
developfrom
bugfix/macos-file-reference-without-finder

Conversation

@gregpriday

Copy link
Copy Markdown
Owner

Summary

On macOS, copying a file reference ran osascript to tell Finder to set the clipboard. That's an Apple Event, and in a terminal without Apple Events access (Daintree, for one) macOS refuses it with -1743 and never prompts. CopyTree then copied the path as plain text and still printed File reference copied, so pasting into ChatGPT gave you a path instead of an attachment.

This writes the file URL to NSPasteboard directly through osascript's JavaScript AppKit bridge, which needs no permission in any terminal, and stops reporting a text fallback as a success.

Changes

  • src/utils/clipboard.js: macOS writes the pasteboard in-process instead of through Finder. writeObjects with an NSURL publishes public.file-url and NSFilenamesPboardType, which is what browsers read for a file paste. The path goes in as an argument after --, so there's no escaping and a leading - isn't read as an option.
  • copyFileReference now resolves { asText, cause } on every platform, so callers know when only the path made it to the clipboard.
  • src/commands/copy.js, src/ui/feedback/model.js: a text fallback reports Path copied as text, not as a file reference with the reason, and fails under --strict (exit 1, like the other clipboard fallbacks).
  • src/commands/ignore.js: ignore context warns the same way.
  • Docs: docs/reference/migrating-to-1.0.md and docs/technical/behavior-ledger.md.

Testing

  • jest over tests/unit/utils, tests/unit/ui/feedback, tests/unit/commands, tests/unit/api/copy, tests/unit/cli and tests/e2e/file-reference: 32 suites, 692 tests pass. New: a cross-platform deliverOutput test, and a macOS e2e that stubs a failing osascript and checks --strict exits 1.
  • npm run lint passes.
  • Checked live from a Daintree terminal: the old script fails with -1743, the new one exits 0, and the pasteboard reads back both the file URL and the filename list.

Codex reviewed it before commit. Its fixes (the -- terminator, first-line error causes, Windows and Linux return assertions, the docs) are in.

- Write the file URL to NSPasteboard from osascript's own process (JXA AppKit bridge) instead of `tell app "Finder"`, which macOS refuses with -1743 and no prompt in terminals that lack Apple Events access, such as Daintree's
- Pass the path as an argument after `--`, so it needs no escaping and a leading dash is not read as an option
- copyFileReference now reports when it could only copy the path as text, with the reason, on every platform
- Report that as "Path copied as text, not as a file reference" rather than "File reference copied", and fail it under --strict (exit 1); ignore context warns the same way
- Cover the fallback with a cross-platform deliverOutput test and a macOS e2e, and document it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant