Enter your email below to get insights on starting, running and growing a creative company

Copying Rails console output to clipboard on Mac

From time to time I want to work with information which is from rails console output outside of the command line. Helpfully, ruby provides a neat way to pipe console output into the mac system clipboard using IO:

IO.popen("pbcopy", "w") do |pipe| 
  # Get users without subscriptions as CSV and add them to the clipboard
  pipe.puts User.includes(:subscription).where(subscriptions: {user_id: nil}).pluck(:email).to_csv
Posted August 2017
© 2014-2018 James Chambers
Learn from my mistakes

Sign up to my mailing list to get insights about starting, running and growing a creative company.