How to use the clipboard in a shell script macro (dumbest question ever)

I have seen the documentation at action:Execute a Shell Script [Keyboard Maestro Wiki] and Clipboards [Keyboard Maestro Wiki] but I just can't put it together.

How do i use the string in the system clipboard in a shell script?
Thanks!

Well, you could set a KM variable to the contents of the system clipboard %SystemClipboard% and then use that variable in your shell script, or you can use the shell commands pbpaste and pbcopy to use the system clipboard directly in the shell. There are man pages for them.

2 Likes

To access the System clipboard from inside a shell script (or Terminal) use pbcopy and pbpaste. Easy to remember -- pb is "pasteboard".

Edit to add: Or, as the super-speedy @tiffle says, use a KM variable as an intermediate.

2 Likes

Thank you, good to know about pbpaste, but also can you please explain the comment

you could set a KM variable to the contents of the system clipboard `%SystemClipboard%

How would this be done?

I have in my shell script this:
echo clipboard is %SystemClipboard%

Wrong apparently...

use a KM variable as an intermediate

How is this done please? Thanks. It seems like it could be useful to know this, even though pbpaste is already a solution.

Here's both ways. Save some text to the clipboard and run:
Clipboard Demo.kmmacros (2.5 KB)

Summary

2 Likes

thank you, that's helpful example code. For those who don't want to install it, here is a screen shot.

Or they could have just clicked the "Summary" disclosure triangle to see an image of the macro...

1 Like