Manipulate Clipboard From Command Line

An easy way to manipulate the clipboard from the command line is by using the pbcopy and pbpaste commands.

pbcopy will copy standard input to the clipboard–the following would be example usages:

echo "MacTips Rocks" | pbcopy (Copies “MacTips Rocks” to the clipboard)
pbcopy < file (Copies the contents of file to the clipboard)
ls -la | pbcopy (Copies the current directory listing to the clipboard)

Similarly, pbpaste will paste the clipboard contents to standard output:

pbpaste (Output the clipboard contents to the screen)
pbpaste > file (Output the clipboard contents to file)

Pbcopy-Pbpaste


 
 

3 Responses to “Manipulate Clipboard From Command Line”

  1. 4Avatars
    Jeremy Kemp
    That, by far, is the coolest tip I have seen here so far. The system actually keeps up with four clipboards, and you can access them independently with this command. 'man pbpaste' gives this:

    [-pboard {general | ruler | find | font}]

    So, with the caveat that the system might overwrite one of the non-general boards, you can use all four to your liking!


  2. Trackback
    blog.syslinx.org » Manipulating clipboard from command line

    [...] Mactips.org provides an nice article on how to manipulate your clipboard from command line. This makes you use commands like this to fill your clipboard: $ echo “fnord” | pbcopy [...]



  3. Trackback

Post a comment to "Manipulate Clipboard From Command Line"