Documentation
¶
Overview ¶
Package clippy provides smart clipboard operations for macOS. It automatically detects whether to copy file content or file references using hybrid detection: UTI -> MIME -> mimetype fallback for maximum reliability.
Example ¶
package main
import (
"fmt"
"log"
"strings"
"github.com/neilberkman/clippy"
)
func main() {
// Copy text to clipboard
if err := clippy.CopyText("Hello, World!"); err != nil {
log.Fatal(err)
}
// Copy a file (text files copy content, others copy reference)
err := clippy.Copy("document.pdf")
if err != nil {
log.Fatal(err)
}
// Copy multiple files
err = clippy.CopyMultiple([]string{"image1.jpg", "image2.png"})
if err != nil {
log.Fatal(err)
}
// Copy from a reader (e.g., from a download)
reader := strings.NewReader("Some text content")
err = clippy.CopyData(reader)
if err != nil {
log.Fatal(err)
}
// Get clipboard content
if text, ok := clippy.GetText(); ok {
fmt.Printf("Clipboard text: %s\n", text)
}
// Get files from clipboard
files := clippy.GetFiles()
for _, file := range files {
fmt.Printf("File in clipboard: %s\n", file)
}
}
Output:
Index ¶
- func CleanupTempFiles(tempDir string, verbose bool)
- func Copy(path string) error
- func CopyData(reader io.Reader) error
- func CopyDataWithTempDir(reader io.Reader, tempDir string) error
- func CopyMultiple(paths []string) error
- func CopyText(text string) error
- func GetFiles() []string
- func GetText() (string, bool)
- type CopyResult
- type PasteResult
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanupTempFiles ¶ added in v0.6.0
CleanupTempFiles removes old temporary files that are no longer in clipboard
func Copy ¶
Copy intelligently copies a file to clipboard. Text files copy their content, binary files copy file references. Uses hybrid detection: UTI -> MIME -> mimetype fallback.
Example ¶
package main
import (
"log"
"github.com/neilberkman/clippy"
)
func main() {
// Copy a single file intelligently
err := clippy.Copy("report.pdf")
if err != nil {
log.Printf("Failed to copy file: %v", err)
}
}
Output:
func CopyData ¶
CopyData copies data from a reader to clipboard. Text data is copied as text, binary data is saved to a temp file. Uses MIME type detection for content analysis.
func CopyDataWithTempDir ¶
CopyDataWithTempDir is like CopyData but allows specifying a custom temp directory.
func CopyMultiple ¶
CopyMultiple copies multiple files to clipboard as file references.
func CopyText ¶
CopyText copies text content to clipboard.
Example ¶
package main
import (
"log"
"github.com/neilberkman/clippy"
)
func main() {
// Copy text to clipboard
if err := clippy.CopyText("Hello from clippy library!"); err != nil {
log.Printf("Failed to copy text: %v", err)
}
}
Output:
func GetFiles ¶
func GetFiles() []string
GetFiles returns file paths from clipboard. Uses hybrid detection for better reliability.
func GetText ¶
GetText returns text content from clipboard. Uses hybrid detection for better reliability.
Example ¶
package main
import (
"fmt"
"github.com/neilberkman/clippy"
)
func main() {
// Get text from clipboard
if text, ok := clippy.GetText(); ok {
fmt.Printf("Clipboard contains: %s\n", text)
} else {
fmt.Println("No text in clipboard")
}
}
Output:
Types ¶
type CopyResult ¶ added in v0.6.0
type CopyResult struct {
Method string // "UTI", "MIME", or "content"
Type string // The detected type (UTI or MIME)
AsText bool // Whether content was copied as text
FilePath string // The file path that was copied
}
CopyResult contains information about what was copied and how
func CopyWithResult ¶ added in v0.6.0
func CopyWithResult(path string) (*CopyResult, error)
CopyWithResult is like Copy but returns information about the detection method used
func CopyWithResultAndMode ¶ added in v0.10.0
func CopyWithResultAndMode(path string, forceTextMode bool) (*CopyResult, error)
CopyWithResultAndMode is like CopyWithResult but allows forcing text mode
type PasteResult ¶ added in v0.6.0
type PasteResult struct {
Type string // "text" or "files"
Content string // Text content if Type is "text"
Files []string // File paths if Type is "files"
FilesRead int // Number of files successfully read/copied
}
PasteResult contains information about what was pasted
func PasteToFile ¶ added in v0.6.0
func PasteToFile(destination string) (*PasteResult, error)
PasteToFile pastes clipboard content to a file or directory
func PasteToStdout ¶ added in v0.6.0
func PasteToStdout() (*PasteResult, error)
PasteToStdout pastes clipboard content to stdout
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
clippy
command
|
|
|
pasty
command
Pasty - Smart paste tool for macOS Companion to clippy, provides intelligent pasting from clipboard
|
Pasty - Smart paste tool for macOS Companion to clippy, provides intelligent pasting from clipboard |
|
Example showing how to use clippy as a library
|
Example showing how to use clippy as a library |
|
internal
|
|
|
pkg
|
|