Pastr is a lightweight, local session-based clipboard manager built for macOS. It lives in your menu bar, providing quick access to your recent clipboard history with intelligent content detection and a clean, modern interface.
UI:
- Pastr respects your Privacy by not tracking any of the copied data at all. No tracking, no analytics, just pure local Clipboard.
- Automatic Clipboard Monitoring: Passively listens for text copied to the pasteboard in the background.
- Intelligent Content Detection: Automatically categorizes clipboard items as Text, URLs, Code Snippets, or Tokens.
- Code Analysis: Recognizes snippets from multiple languages (Swift, Python, Java, JavaScript, SQL) and formats (JSON, Shell).
- Token Recognition: Identifies various token types, including JWTs, UUIDs, and common API keys (e.g., GitHub, Stripe).
- Session-Based History: Non-pinned items are automatically cleared after a configurable session (default: 5 minutes), keeping your history relevant and clean.
- Persistent Timer: The session timer runs continuously from app launch, resetting automatically when a new item is added to an empty clipboard.
- Pinning: Pin important items to keep them indefinitely. Pinned items are always shown at the top and are excluded from automatic session clearing.
- Search & Filtering: Quickly find items with a full-text search and one-click filters for Code, URLs, and Tokens.
- Modern UI: Built entirely with SwiftUI for a responsive and native macOS experience.
- Safe & Efficient: Uses modern Swift Concurrency (
async/await,Task) for safe and efficient background processing, avoiding race conditions and ensuring the UI remains smooth.
Pastr is built around a central data model and a declarative UI, following modern Swift development practices.
- The entire application state is managed by a single
@MainActor-isolatedObservableObjectcalledClipboardManager. This class is the single source of truth. - It's responsible for:
- Monitoring the
NSPasteboardfor changes. - Storing the list of
ClipboardItems. - Handling business logic like pinning, clearing the session, and copying items back to the pasteboard.
- Managing the continuous session timer loop.
- Monitoring the
- The user interface is built declaratively with SwiftUI.
- The main
ContentViewobserves theClipboardManagervia@EnvironmentObjectand assembles the various sub-views (HeaderView,FooterView,SearchAndFilterView, etc.). - Data flows unidirectionally from the
ClipboardManagerto the views. User actions in the views call methods on the manager to mutate the state.
- Instead of traditional
Timerobjects, the app usesTaskandawait Task.sleep(for:)for all periodic operations (pasteboard checking, session management, and auto-cleanup of old items). - This approach is safer, avoids potential threading issues with
@MainActor, and is more integrated with the Swift language.
- The "smart" part of Pastr lives in the
ContentAnalyzerstruct. - It uses a chain-of-responsibility approach to identify content, starting with the most specific types (URLs, Tokens) and falling back to more general ones.
- For code analysis, it employs the Strategy Pattern. Each language/format has its own
CodeAnalysisStrategyobject. This makes the system incredibly easy to extend—to add support for a new language, you simply create a new strategy struct without modifying the existing analyzer.
- Clone the repository.
- Open
Pastr.xcodeprojin Xcode. - Select a team for code signing in the "Signing & Capabilities" tab.
- Press
Cmd+Rto build and run the application.
- Hotkey implementation for quick access on anywhere in the system when app is in background.
Made with ❤️ and Swift.
Fatin.
