1
$ cat scaswd.pdf| pbcopy
$ pbpaste > astasd.pdf
$ open astasd.pdf

astasd.pdf cannot be opened, but scaswd.pdf is a valid pdf file.

Is there a way I can stick a pdf onto my clipboard and paste it somewhere else?


I want to copy a file from my local computer to a remote one I can only access with ssh, without using intermediary file-hosting servers.

(I can't scp)

For text files copy and pasting between terminals works.

For binary files, like a pdf, I need another solution.

8
  • 1
    I think that mac doesnt support file copying this way. What are you trying to achieve? if you want to copy files in terminal there are easier ways. Commented Nov 28, 2018 at 16:56
  • @BenjaminScherer copy a file from my computer to a remote computer I can only access with ssh (I can't scp)
    – user150109
    Commented Nov 28, 2018 at 18:43
  • Do you have rsync? Commented Nov 28, 2018 at 18:46
  • @BenjaminScherer yes
    – user150109
    Commented Nov 28, 2018 at 20:16
  • 1
    @BenjaminScherer won't work for the same reason scp doesn't work, the computer I need to copy to isn't accessible on the internet. I ssh to one computer, then I ssh to another one from that computer's local network. I guess I could do a 2-step rsync or scp
    – user150109
    Commented Nov 28, 2018 at 20:54

3 Answers 3

2

From the man page of pbcopy

pbcopy takes the standard input and places it in the specified pasteboard. If no pasteboard is specified, the general pasteboard will be used by default. The input is placed in the pasteboard as plain text data unless it begins with the Encapsulated PostScript (EPS) file header or the Rich Text Format (RTF) file header, in which case it is placed in the pasteboard as one of those data types.

So from this it would seem that only documents with RTF format or EPS format can be copied and pasted from these commands.

Finder does support copy and pasting files however, so cmd c, and cmd v, will copy and paste files in finder.

2

You can cat the pdf file and redirect the output to a file without using the clipboard.

cat scaswd.pdf > astasd.pdf; open astasd.pdf
-1

Partial or preliminary answer, needs work on the exact syntax, scripting experts, please help:

The clipboard can do a bit more than the manpage for pbcopy and pbpaste reveals. Obviously, most of us have copied and pasted something else then pure text. Pictures for example.

You might try something like this:

osascript -e 'set the clipboard to (read POSIX file ("/Users/YOU/test.pdf") as PDF file)'

The above is not the correct syntax near às PDF file` and will throw an error. But it works for JPEG files, PNGs etc.

Leaving out the latter part with the slightly incorrect input-syntax copies 'something' to the clipboard. Checking the content with `osascript -e 'clipboard info' gives then not something like

Unicode text, 92, string, 46, styled Clipboard text, 22, «class utf8», 46, «class ut16», 94

but

astasd.pdf: PDF document, version 1.4

Only that this is then not copied out correctly.

`

You must log in to answer this question.