https://github.com/psenger/copy-to-clipboard
macOS Service — right-click any text file in Finder to copy its contents to the clipboard
https://github.com/psenger/copy-to-clipboard
clipboard context-menu finder-extension findersync macos macos-utility swift xcode
Last synced: 9 days ago
JSON representation
macOS Service — right-click any text file in Finder to copy its contents to the clipboard
- Host: GitHub
- URL: https://github.com/psenger/copy-to-clipboard
- Owner: psenger
- License: mit
- Created: 2026-04-26T06:01:46.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2026-04-26T11:46:37.000Z (2 months ago)
- Last Synced: 2026-06-18T03:33:57.249Z (9 days ago)
- Topics: clipboard, context-menu, finder-extension, findersync, macos, macos-utility, swift, xcode
- Language: Swift
- Size: 165 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# copy-to-clipboard

**A macOS Services helper that puts any text file's contents on the clipboard — right from Finder.**


[](./LICENSE)
[Installation](#installation) • [Usage](#usage) • [How it works](#how-it-works) • [Development](#development)
---
Right-click any text file in Finder, choose **Services → Copy Contents to Clipboard**, and paste.
No app to open, no window to close. A Tink sound confirms the copy; a Basso sound means the
file was unreadable or binary.
The app handles UTF-8, UTF-16, and Windows-1252 files. It has no UI, no menu-bar icon, and no
persistent process — macOS wakes it on demand and exits it after each invocation.
## Installation
```bash
make install
```
Builds the Release app, copies it to `~/Applications`, and re-applies ad-hoc code signing.
The app registers itself with the macOS Services menu on first launch — no further setup needed.
> **Gatekeeper:** Ad-hoc signed apps are blocked on first open. Right-click the app in Finder,
> choose **Open**, and confirm once. macOS remembers the choice.
## Usage
1. Right-click any text file in Finder (`.swift`, `.py`, `.md`, `.json`, `.txt`, …)
2. Choose **Services → Copy Contents to Clipboard**
3. Paste anywhere
The service appears only for files whose UTI conforms to `public.text`. Binary files —
images, archives, executables — are silently rejected.
**Encoding support**
| File | How it's read |
|---|---|
| UTF-8 (with or without emoji) | Auto-detected |
| UTF-16 (with BOM) | Auto-detected |
| Windows-1252 / legacy Windows text | Explicit fallback after auto-detection fails |
## How it works
`copy-to-clipboard` is a launch-on-demand macOS Service. There is no persistent process.
```
Finder right-click
└─ macOS Services framework
└─ AppDelegate.copyFileContents(_:userData:error:)
└─ ClipboardService.copy(fileAt:)
├─ Reject non-public.text UTIs
├─ String(contentsOf:usedEncoding:) ← UTF-8 / UTF-16
├─ String(contentsOf:encoding:.windowsCP1252) ← Windows fallback
└─ NSPasteboard.general.setString(_:forType:.string)
```
**Why `setString` and not `setData`?** Writing raw file bytes to the pasteboard causes emoji
and multi-byte Unicode to paste as garbage. Decoding the file to a Swift `String` first means
paste targets always receive Unicode regardless of the original file encoding.
## Development
```bash
git clone https://github.com/psenger/copy-to-clipboard.git
cd copy-to-clipboard
make test # 11 tests, ~91% line coverage
make build # Release build → build/Build/Products/Release/
```
See [CONTRIBUTING.md](./CONTRIBUTING.md) for the full development guide, key invariants,
and architecture decisions.
## License
[MIT](./LICENSE) © 2026 Philip Senger
---
**For developers who work with text files.**
[Report Bug](https://github.com/psenger/copy-to-clipboard/issues) • [Request Feature](https://github.com/psenger/copy-to-clipboard/issues) • [Contributing](./CONTRIBUTING.md)