From 3abfa92b64bc3a65a7f525df29691e59dd0e4c09 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sun, 1 Dec 2024 09:58:15 -0600 Subject: [PATCH] Add Write System Clipboard To A File as a Mac TIL --- README.md | 3 ++- mac/write-system-clipboard-to-a-file.md | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 mac/write-system-clipboard-to-a-file.md diff --git a/README.md b/README.md index 2cb3c91..6801c9d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1522 TILs and counting..._ +_1523 TILs and counting..._ --- @@ -637,6 +637,7 @@ _1522 TILs and counting..._ - [Specify App When Opening From Command Line](mac/specify-app-when-opening-from-command-line.md) - [Use Default Screenshot Shortcuts With CleanShot X](mac/use-default-screenshot-shortcuts-with-cleanshot-x.md) - [View All Windows Of The Current App](mac/view-all-windows-of-the-current-app.md) +- [Write System Clipboard To A File](mac/write-system-clipboard-to-a-file.md) ### MongoDB diff --git a/mac/write-system-clipboard-to-a-file.md b/mac/write-system-clipboard-to-a-file.md new file mode 100644 index 0000000..f36d1ae --- /dev/null +++ b/mac/write-system-clipboard-to-a-file.md @@ -0,0 +1,19 @@ +# Write System Clipboard To A File + +MacOS has two CLI utilities `pbcopy` and `pbpaste` which, respectively, copy +_to_ and paste _from_ the system clipboard via the CLI. + +Let's say I've just copied a large block of text from somewhere onto my system +clipboard. I now want to paste that into a new file. Instead of creating a new +file, opening it up in my preferred editor, pasting all that text, and saving +the file, I can run one small command from the CLI. + +```bash +$ pbpaste > data.txt +``` + +This redirects the contents of `pbpaste` (which is the system clipboard) into +the file `data.txt`. If that file doesn't already exist, then it will be +created before the data is written to it. + +See `man pbpaste` for more details.