Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Places the clipboard contents into a text file then launches the text file to open it in the default editor.
#!/usr/bin/env ruby
# Places the clipboard contents into a new temp text
# file and opens the text file in the default text editor
require 'ftools'
# find an unused file name
a = 1
folder = File.expand_path "~/Documents/texts/temp"
File.makedirs folder unless File.exist? folder
begin
file = "%s/tmp%04d.txt" % [folder, a]
a += 1
end while File.exist? file
# obtain clipboard contents
clip = IO.popen('pbpaste', 'r+').read
# write contents to a file
File.open(file, 'w') {|f| f.write(clip) }
# let the user know what the file name is
puts file
# open the file in default text editor
system("open", file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment