Skip to content

Instantly share code, notes, and snippets.

@nuclearsandwich
Forked from noahcoad/cliptext.rb
Last active December 10, 2015 02:58
Show Gist options
  • Save nuclearsandwich/4371592 to your computer and use it in GitHub Desktop.
Save nuclearsandwich/4371592 to your computer and use it in GitHub Desktop.
change tabs to two spaces. part deux
#!/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