Here is an example of setting the clipboard to an image. Obviously just edit the image path.
osascript -e 'set the clipboard to (read (POSIX file "/Library/Desktop Pictures/Mojave Day.jpg") as JPEG picture)'
In Terminal.app, you could also create a function
named copy
(or whatever you want to name it) with this following line of code.
copy(){ osascript -e 'on run{a}' -e 'set the clipboard to posix file a' -e end "$(readlink -f "$1")"; }
Then you would have a new command called copy
which would take an argument which would be passed to the osascript
.
For example, you could set a variable
to the result of a command which returns the path of a file you would like to set your clipboard to. Then you could use that variable
as the argument to your copy
command.
This following command sets the new variable
theFile to the results of the find "/Library/Desktop Pictures" -name "Mojave Day*"
command.
theFile="$(find "/Library/Desktop Pictures" -name "Mojave Day*")"
OK so now you have created your copy
function. You also now have a variable
called theFile
. Now all you need to do to copy the file to your clipboard as an actual file and not just the path of the file as text, is to use your new copy
command using theFile
variable as it's argument... like this
copy "$theFile"
Or maybe you don't want to pass a variable
to the copy
command. You could just as easily use the full POSIX Path of the file instead as the argument to the copy
command like this...
copy "/Library/Desktop Pictures/Mojave Day.jpg"
So maybe my examples are not true "Pipes" but they are a way of passing information to the osascript
command.
SIDENOTE: This will only work on single files or folders, not multiple files/folders.