Hasty Briefsbeta

Bilingual

Copying Remote Command Output to Your macOS Clipboard

2 days ago
  • The user finds macOS's pbcopy command useful for copying file contents to clipboard from the shell.
  • pbcopy only works locally on Mac; it is unavailable on remote servers accessed via SSH.
  • A solution uses the OSC 52 terminal escape sequence to copy text from remote servers to the local clipboard.
  • The script works with iTerm2 and other OSC 52-compatible terminals (e.g., kitty, Ghostty), but not Apple's Terminal.app.
  • iTerm2 requires enabling 'Applications in terminal may access clipboard' in Settings for this to work.
  • The remote script is a simple shell script that base64-encodes input and outputs the OSC 52 sequence.
  • The script is created on the remote server (e.g., /usr/local/bin/pbcopy) and made executable.
  • This method has security implications as any terminal program could access the local clipboard.