minton
1
I have a simple .exs
script that generates a string based on some inputs. How would I get that onto the system clipboard on macOS.
Here’s what I have so far:
- Gather input from the user via
IO.gets/1
- Write the output to a file temp using
File.write/3
- Run a bash script that outputs that temp file to
pbcopy
This technically works but there must be a better way that I wouldn’t be ashamed of. Any help would be very much appreciated.
minton
3
Hi, thanks for the response!
I first thought I could do something like $ elixir go.exs | pbcopy
but that won’t work because it gets stuck waiting for user input.
outlog
4
you can use a Port https://hexdocs.pm/elixir/Port.html
eg:
port = Port.open({:spawn, "pbcopy"}, [:binary])
send port, {self(), {:command, "hello"}}
send port, {self(), :close}
will put hello in your clipboard
4 Likes
minton
5
That worked perfectly. Thanks for help!
1 Like