It works for me on MacOS. e.g. putting the code below into a file
capture.jl, then running
julia capture.jl
I can then type e.g. display("foo") and "foo" gets included in the text
copied to the clipboard.
#####################################################
const orig_STDOUT = STDOUT
rdstdout, wrstdout = redirect_stdout()
pushdisplay(TextDisplay(STDOUT))
while true
try
result = eval(Base.parse_input_line(STDIN))
println("RESULT = ", result)
catch e
print("EXCEPTION = ")
Base.showerror(STDOUT, e)
end
s = readavailable(rdstdout)
clipboard(s)
print(orig_STDOUT, s)
end