Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy a string to clipboard from Mac OS command line

is there a way to copy a string to clipboard from command line?

To be more specific, I want to make a script which copies my email address to clipboard, so that when I need to insert it several times for logging in / register, I just run the script once and then CMD+V it whenever I need.

I heard of pbcopy, but I think this is not my case. Any suggestion? Many thanks!

like image 242
Andrea Ottaviani Avatar asked Sep 25 '16 23:09

Andrea Ottaviani


People also ask

How do you copy and paste on a Mac command line?

To copy something on Mac, select it and press Command + C . This copies your data or item to clipboard, and you can paste it where you need it. Use Command + V to paste. If you want to remove a piece of text or a file as you are copying it, simply swap out the Command + V for Command + X .

How do I copy cat to clipboard on Mac?

I could have opened another text editor and then copy and pasted the lines but this is so inconvienient. In Mac OS X you can use a command called pbcopy for situations like these. Now the output given by the cat command got transfered into the clipboard and can be pasted wherever you want it.

Can you copy paste in Terminal Mac?

You can copy and paste text from other documents into a Terminal window. Note: If the text being pasted includes the return character at the end of a line, the command is executed immediately. In the Terminal app on your Mac, do any of the following: Copy text in another app, and then in Terminal choose Edit > Paste.


1 Answers

You need to pipe the output of your script to pbcopy

For example:

./somescript.sh | pbcopy
like image 110
Chad Dienhart Avatar answered Oct 18 '22 16:10

Chad Dienhart