-2

I work primarily in terminal but I do communicate with others in GUI apps, e.g. Slack. Sometimes I got some logs / events and I piped them into a file, I can copy the file content to clipboard easily but I can not find a way to copy the file itself, any idea?

I've tried pbcopy, cat and piping around, no luck.

Alex_Xie
  • 1
  • 1
  • 1

1 Answers1

0

If I understand what you're trying to do (essentially, the equivalent of selecting a file in Finder and choosing Edit menu > Copy), this should work:

osascript -e 'on run argv' -e 'set the clipboard to item 1 of argv as «class furl»' -e 'end run' /path/to/file

Note that I don't think this'll work with relative paths or bare filenames. If you want to make this into a script or function, you should probably add a step to convert relative paths to asolute... which is tricky on macOS since it doesn't have realpath and its readlink doesn't have the -f option. See "How to retrieve absolute path given relative" and the linked duplicate questions.

Also, for completeness, if you just want to copy the contents of a file as text, it's much easier: pbcopy </path/to/file

Gordon Davisson
  • 118,432
  • 16
  • 123
  • 151