Skip to content

Instantly share code, notes, and snippets.

@noahcoad
Created December 17, 2012 04:53
Show Gist options
  • Save noahcoad/4315822 to your computer and use it in GitHub Desktop.
Save noahcoad/4315822 to your computer and use it in GitHub Desktop.
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