1

I'm using curl and grep to get the URL of an image, after that I'd like to download the image itself, and copy it to the clipboard directly, rather than saving it to the disk temporarily before. I'm puzzled that the output doesn't seem to work. It only gives me "text" rather than the image itself. Here's the command I have so far:

curl -s https://www.tradingview.com/x/4WuY06rl/ | grep -oE "src='[^']+'" | sed -E "s/src='([^']+)'/\1/" | xargs curl -s | pbcopy

If there's an easier solution to this, please let me know. The command is built around the idea that the website here has only ONE img tag.

3
  • 1
    IIRC pbcopy works only with text-based data.
    – nohillside
    Feb 11 at 10:35
  • I think you want this: stackoverflow.com/questions/6919403/…
    – Alex
    Feb 12 at 1:14
  • Thank you for the suggestions. I solved it now by creating a temporary file, and then reading that file.
    – Zettt
    Feb 14 at 7:31

1 Answer 1

1

To answer my own question. In the end I settled for, grudgingly, write the image to a fixed file in /tmp, and then read that image into the clipboard using AppleScript. That was just easier than messing around with uuencode. Thank you for all the suggestions.

curl -s https://www.tradingview.com/x/4WuY06rl/ | grep -oE "src='[^']+'" | sed -E "s/src='([^']+)'/\1/" | xargs curl -s -o /tmp/tvimg.png & osascript -e 'set the clipboard to (read (POSIX file "/tmp/tvimg.png") as «class PNGf»)'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .