Requirements
- macOS 15.0 (Sequoia) or later
- Swift 6.2 or later (for building from source)
Install via Script
The easiest way to install pngpaste is via the install script. It automatically detects your architecture (Intel or Apple Silicon) and downloads the appropriate binary.
# Install via curl (recommended)
curl -fsSL https://raw.githubusercontent.com/yriveiro/pngpaste/main/scripts/install.sh | bash
# Or with explicit confirmation skip
curl -fsSL https://raw.githubusercontent.com/yriveiro/pngpaste/main/scripts/install.sh | bash -s -- --yes
# Custom install directory
curl -fsSL https://raw.githubusercontent.com/yriveiro/pngpaste/main/scripts/install.sh | bash -s -- --bin-dir ~/.local/bin
# Verify installation
pngpaste --version
Build from Source
Clone the repository and build using Swift Package Manager. The release build is optimized for performance.
For development and testing
Optimized for production use
# Clone the repository
git clone https://github.com/yriveiro/pngpaste.git
cd pngpaste
# Build (debug)
swift build
# Build (release)
swift build -c release
# Run directly
swift run pngpaste output.png
# Install to /usr/local/bin
cp .build/release/pngpaste /usr/local/bin/
Basic Usage
Copy an image to your clipboard (e.g., screenshot with
Cmd+Shift+4
or copy from any application), then use pngpaste to save it.
Output Modes
- File: Save to a specific path
- Stdout: Pipe binary output
- Base64: Output as base64 string
# Save clipboard image to PNG file
pngpaste screenshot.png
# Save as JPEG (format determined by extension)
pngpaste photo.jpg
# Save as GIF
pngpaste animation.gif
# Output to stdout (pipe to another command)
pngpaste - | convert - -resize 50% smaller.png
# Output as base64 (useful for embedding)
pngpaste -b | pbcopy
# Combine with other tools
pngpaste - | base64 | curl -X POST -d @- api.example.com/upload
Error Handling
pngpaste provides clear error messages when something goes
wrong. Exit code 0 indicates
success, non-zero indicates an error.
Common Errors
- No image: Clipboard is empty or contains text
- Unsupported format: Clipboard contains unsupported image type
- Write failure: Cannot write to the specified path
# Check if clipboard has an image
if pngpaste /tmp/test.png 2>/dev/null; then
echo "Image saved successfully"
else
echo "No image on clipboard"
fi
# Example error messages:
# pngpaste: no image data found on the clipboard
# pngpaste: failed to write to '/path': Permission denied
# pngpaste: clipboard contains unsupported image format