Skip to content

Instantly share code, notes, and snippets.

@noahcoad
Created November 30, 2012 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noahcoad/4174197 to your computer and use it in GitHub Desktop.
Save noahcoad/4174197 to your computer and use it in GitHub Desktop.
Ruby script that places the clipboard contents into a new temp text file and opens the text file
#!/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