| 1 | # Clipboard Integration |
| 2 | |
| 3 | Nearly every operating system has some notion of a short-term storage area which can be accessed by |
| 4 | any program. Usually this is called the :clipboard: clipboard, but sometimes people refer to it as |
| 5 | the paste buffer. |
| 6 | |
| 7 | `cmd2` integrates with the operating system clipboard using the |
| 8 | [pyperclip](https://github.com/asweigart/pyperclip) module. Command output can be sent to the |
| 9 | clipboard by ending the command with a greater than symbol: |
| 10 | |
| 11 | ```text |
| 12 | mycommand args > |
| 13 | ``` |
| 14 | |
| 15 | Think of it as redirecting the output to an unnamed, ephemeral place: the clipboard. You can also |
| 16 | append output to the current contents of the clipboard by ending the command with two greater than |
| 17 | symbols: |
| 18 | |
| 19 | ```text |
| 20 | mycommand arg1 arg2 >> |
| 21 | ``` |
| 22 | |
| 23 | !!! warning "Limitation" |
| 24 | |
| 25 | The ability to redirect command output only works directly from a `cmd2` |
| 26 | command. It doesn't work after piping output to a shell command. |
| 27 | |
| 28 | ## Developers |
| 29 | |
| 30 | You can control whether the above user features of adding output to the operating system clipboard |
| 31 | are allowed for the user by setting the [cmd2.Cmd.allow_clipboard][] attribute. The default value is |
| 32 | `True`. Set it to `False` and the above functionality will generate an error message instead of |
| 33 | adding the output to the clipboard. [cmd2.Cmd.allow_clipboard][] can be set upon initialization, and |
| 34 | you can change it at any time from within your code. |
| 35 | |
| 36 | If you would like your `cmd2` based application to be able to use the clipboard in additional or |
| 37 | alternative ways, you can use the following methods (which work uniformly on Windows, macOS, and |
| 38 | Linux). |
| 39 | |
| 40 | ::: cmd2.clipboard |